One minute
Cheatsheet : git
A collection of git notes i usually have to lookup
Create a new local branch and push to remote
git checkout -b <newbranch>
[make changes]
git add [changed files]
git commit -m "[sensible message]"
git push origin <newremotebranch>
Remove any local branches that dont exist on remote
git fetch -p [or --prune]
Show staged files
View changes that have been added but not commited:
git diff --staged
Update submodules
Update submodules to the latest versions (assuming they are already initialised with git submodule init):
git submodule update --remote
[and if you want to push the updates back up]
git add .
git commit -m"[sensible message]"
git push
Patching main and long running feature branches without cherry picking
If you want to
git merge-base main feature
Create a new branch from the common merge base:
git checkout -b patch main <common base>
git checkout patch
Check you’ve got the right merge base by confirming you only see the expected changes:
git log master..patch
git log feature..patch
PR your changes into the main and feature branches as normal.
There’s a really in depth description of why cherry picking should be avoided from Raymond Chen at Microsoft.