Random Git tips
A collection of unrelated but useful Git tips.
git adog
I find git adog
and git dog
to be the best way to quickly explore the log.
git config --global alias.adog "log --all --decorate --oneline --graph"
git config --global alias.dog "log --decorate --oneline --graph"
Branch from Master
Usually there’s a master/develop branch which contains the latest working development version. New features and other changes should be developed in a new branch created from the master. Each feature branch should have the same name as its corresponding ticket in JIRA or similar.
Merging and conflict resolution
To merge branchA to branchB:
git checkout branchB
git merge branchA
When conflicts appear, to keep the branchA version of a file
git checkout --theirs path/to/file
To keep the branchB version of a file
git checkout --ours path/to/file
Rebase and squash easily with Vim
- Go to the beginning of the line with the first commit you want to squash
- Enter visual block mode (
CTRL-V
) - Select all the commits you want to squash
- Press
c
and types
to replace thepick
command - Press
ESC
to apply the change to all the selected rows
Leave a comment