The list of Git commands that tackle most everyday routines.
Branches
The commands to work with local and remote branches.
Pull and rebase
1 |
git pull --rebase=i origin feature-1 |
Commit difference between branches
1 |
git log origin/develop..origin/master --oneline |
Overwrite remote branch with local branch
1 2 |
git checkout local-feature-branch git push -f origin HEAD:remote-feature-branch |
Useful when it’s need to do restore from local branch.
Commits count between branches
1 |
git rev-list --left-right --count origin/branch-1...origin/branch-2 | cut -f1 |
--no-merges
parameter allow to count without merge commits
Get files from another branch
1 2 3 |
git checkout master # copy the version of app.js from branch experiment git checkout experiment -- app.js |
Git Diff
Use this commands if it needs to find differencies in your worktree code.
Diff between branches
1 |
git diff origin/feature-1..origin/feature-2 |
Diff of a file between branches
1 |
git diff feature-branch-20:path/MyFile.php a03b091759:path/MyFile.php |
Find diff files by search string
1 |
git diff -GmyCoolCodeString origin/master --name-only |