git command collection
Basics
- Avoid merge commits by using rebase.
- Squash multiple trivial commits into a single commit.
- Write a the perfect commit message
Writing a feature
Branch from main
git checkout maingit pullgit checkout -b <branch-name>
Rebase upstream often to avoid conflicts
git fetch origingit rebase origin/main
In case of multiple commits rebase interactively
git rebase -i origin/main
Commit with the perfect commit message
Merging branches
Rebase from main
git fetch origingit rebase -i origin/main
Force push your branch
git push --force-with-lease origin <branch-name>
View a list of new commits. View changed files. Merge branch into main.
git log origin/main..<branch-name>git diff --stat origin/maingit checkout maingit merge <branch-name> --ff-onlygit push