Making Git less of a Git

Sick of me using the Googles for commands I don't use all the time but want to keep track of.

Ah why does commit message open in [vim, nano]

Easy to change, even open in VS Code etc. I prefer vim. Also I don't like doing -m, writing in an editor with the ability to cancel has saved me a few times.

git config --global core.editor "nano"

OH No! I commited to my local master

As long as you haven't pushed, its OK.

git reset --soft HEAD^

Then branch and commit as usual.

Show me the logs

Some nice log formats:

git log --pretty=oneline
git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago'
git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short

Ah, what branches do we have?

Show remote/local branches:

git branch -a // shows all branches on local and remote
git branch -r // shows remote branches

Yeah, I need to remove that branch from remote

git push origin --delete branch_name

Shit, typo in my branch name

git branch -m newname

How do I add origin again?

git remote add origin blahblah.git

Yeah, but I want to branch from that one

git checkout -b myFeature otherbranch 

Stash

git stash

List all stashes:

git stash list

Apply last stash:

git stash apply

Apply a particular stash:

git stash apply stash@{2}

I find it better to name my stashes:

git stash create this is my stash message

I just want to patch something

//create a patch
git diff > fix.patch

//check for conflicts git apply --check fix.patch

//good to go git apply patch.patch

Diffing two branches

Note the ..., there are no spaces:

git diff master...branch

I want to ignore that file now

Sometimes you have a config file that might change from developer to developer, but you want a base file. Great, just use this:

git update-index --skip-worktree [<file>]

Line endings

Pesky line endings when moving from *nix to windows vice versa:

git config --global core.autocrlf true

Resources