My Git cheat sheet

INIT

Init an empty Git repository or reinitialize an existing one

git init

Clone a repository

git clone https://mygitbucket.com/niklas/my_project.git

Pull in new changes from remote

git pull

Do a dry-run fetch to see what is comming

 git fetch --dry-run

BRANCH

Create a branch locally and checkout the branch

git checkout -b <name of branch>

Push the branch to remote

 git push origin <name of branch>

Delete local branch

git branch -d <name of branch>

Delete remote and local

git branch -D <name of branch>

Show all branches

 git branch -a

List all remotes

git remote -v

Rename a local branch that you have checked out

git branch -m <new name>

Rename a branch you have not checked out

git branch -m <old name> <new name>

SUBTREE

Add a remote subtree to your project. ‘common’ is here the name of the subtree

git remote add common https://mygitbucket.com/niklas/my_project.git

Do a ‘common pull’ i.e. pull a remote branch into to subtree. ‘common’ is here the name of the subtree (and folder)

git subtree pull -P common common my-subtree-branch --squash

LOG

Pretty print log with oneline

git log --pretty=oneline

Git log with graph

git log --all --decorate --oneline --graph

Check commits only in the current branch (descendent to master)

git log master..

Check commits that differ between branches (descendent to other branch)

git log master..<name of branch>

PATCH

Create patch files for every commit in a interval of SHA’s

git format-patch <start SHA>..<stop SHA>

HEAD and other short codes work too
Create ONE patch file for all commits in the last 10 commits (from HEAD and back)

git format-patch -10 HEAD --stdout > my.patch

Apply a patch

git apply my.patch

STASH

Show the content of your current stash

git stash show

Show a diff of the content of your stash and current code base

git stash show -p

Stash all uncommited modifications

git stash

Apply last saved stash to your current code

git stash apply

Apply last saved stash to your current code AND delete the stash

git stash pop

Manually delete the stash

git stash drop

TAG

List all tags

git tag

Create a “lightweight” tag

git tag <tag name> <SHA*>

* SHA is optional. Without it you will tag the place you are at
Create a “heavyweight” tag

git tag -a <tag name> -m <message> <SHA*>

* SHA is optional. Without it you will tag the place you are at
Remove a tag

git tag -d <tag name>

MISC

List all commits waiting to get pushed

git cherry -v

Disable ssl verification on a specific domain

git config --global http."https://git.niklasottosson.com/".sslVerify false

Remove folder in Git and leave folder intact on disc

git rm -r --cached <folder>

-r is needed for folders (not files)
–cached is the magic the leaves the folder on disc and only removes it from Git

Set new http adress to origin

git remote set-url origin <new url eg. http://github.com/newrepo.git>

This changes both the (fetch) and (push) url for origin in your local repository

My iKeycmd cheat sheet

# Add a client certificate to the Queue manager keystore (using stashed password)
ikeycmd -cert -add -db "key.kdb" -label ibmwebspheremqclient01 -file ibmwebspheremqclient01.crt -format ascii -stashed

# Remove certificate from Queue manager keystore (using stashed password)
ikeycmd -cert -delete -label ibmwebspheremqclient01 -db "key.kdb" -stashed

# Set default certificate (using stashed password)
ikeycmd -cert -setdefault -db key.kdb -stashed -label "mydefaultcertificate"

# List certificates
ikeycmd -cert -list personal -db "key.kdb" -pw changeit
ikeycmd -cert -list ca -db "key.kdb" -pw changeit

* List default signers
ikeycmd -cert -listsigners

Tested on IBM MQ 7.0.1.0 and Red Hat Linux 7

My Java Keytool cheat sheet

# List all entries in a JKS
keytool -list -keystore mykeystore.jks -storepass changeit

# List all entries in a PKCS12
keytool -list -keystore mykeystore.jks -storepass changeit -storetype pkcs12

# List detailed information about all entries in a JKS
keytool -list -v -keystore mykeystore.jks -storepass changeit

# Rename an alias in a JKS
keytool -changealias -alias "client01" -destalias "client02" -keystore mykeystore.jks -storepass changeit

# Remove an alias in a JKS
keytool -delete -alias "client01" -keystore mykeystore.jks -storepass changeit

# Create a JKS with a self-signed certificate
keytool -genkey -keyalg RSA -alias client01 -keystore mykeystore.jks -storepass changeit -validity 365 -keysize 2048

# Create a JKS and import certificate from file (if keystore does not exist it will be created)
keytool -keystore mykeystore.jks -storepass changeit -import -file mycertfile.crt

# Import a certificate to trust to a jks
keytool -import -alias server01 -file server01.crt -keystore mykeystore.jks

# Change JKS keystore password
keytool -storepasswd -keystore mykeystore.jks

# Change a JKS key's password:
keytool -keypasswd  -alias <key_name> -keystore mykeystore.jks

# Extract certificate from a jks keystore
keytool -export -keystore mykeystore.jks -alias client01 -file client01.crt

# Convert a PKCS12 (p12) certificate to JKS
keytool -importkeystore  
  -srckeystore mysourcekeystore.p12 
  -destkeystore mydestkeystore.jks 
  -srcstoretype PKCS12 
  -deststoretype JKS 
  -srcstorepass mysourcepassword 
  -deststorepass mydestpassword 
  -srcalias mysourcecertalias 
  -destalias mydetscertalias 
  -srckeypass mysourcekeypassword 
  -destkeypass mydestkeypassword

# Convert a JKS keystore to a PKCS12 keystore
keytool -importkeystore 
  -srckeystore mykeystore.jks 
  -destkeystore mykeystore.p12
  -deststoretype pkcs12 

# Generate a self-signed certificate and put it into a JKS (valid for 720 days)
keytool -genkey 
  -keyalg RSA 
  -alias server 
  -keystore selfsigned.jks 
  -validity 720 
  -keysize 2048

Tested on Red Hat 7 and Java 8