Skip to content

Git Wiki

Pretty git log

alias gl='git log --all --color --graph --pretty=format:'"'"'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"'"' --abbrev-commit'

More here.

See git log for specific branch

First, use git log with fancy coloring.

alias glb='git log --color --graph --pretty=format:'"'"'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"'"' --abbrev-commit'

More here.

Usage:

glb origin/master..some branch

Remove untracked files

# dry run
git clean somedirectory -n
# deletes files
git clean somedirectory -f

Get changes from a branch to a specific directory

git checkout some_branch some_dir
# will only update some_dir with changes from some_branch

Git push default behaviour

Git's default is simple. In this mode, pushes the current branch to its upstream branch, but refuses to push if the upstream's branch name is different from the local one.

git config --global push.default current

Pushes the current branch to a remote branch of the same name.

More.

Git stash

git stash save "message"
git stash list
git stash apply stash@{1}

git checkout stash@{1} -- somedirectory
# only apply stash changes to specific files

# interactive mode
git stash save -p "my commit message"

# see stashed files
git stash show stash@{1}

# see stash contents
git stash show -p stash@{1}

More.

Squash last n commits

git reset --soft HEAD~n
git commit -m "new message"

More here.