Skip to content

Tips and Tricks

Rename branch

Renamed to new_name

git branch -m <new_name>

Push and reset

git push origin -u <new_name>

Delete remote branch

git push origin --delete <old>

Log

Search change by content

git log -S'<a term in the source>'

Show changes over time for specific file

git log -p <file_name>

Print out a cool visualization of your log

git log --pretty=oneline --graph --decorate --all

Branch

List all branches and their upstreams

git branch -vv

Quickly switch to the previous branch

git checkout -

Get only remote branches

git branch -r

Checkout a single file from another branch

git checkout <branch> -- <file>

Rewriting history

Rewrite last commit message

git commit --amend -m "new message"

Amend the latest commit without changing the commit message.

git commit --amend --no-edit

See also: Rewriting history

Git Aliases

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status

See also: More Aliases

Comments