Helpful git manual available at GitHub.
Clean up branches after merge
These steps are intended to be used only after your branch has already been merged to ‘master’ and the remote branch has been deleted.
Step 1: Update available branches
Step 2: Go back to master
Leave your local brance and go back to origin/master.
git checkout master
git pull
You should be now up to date with the master branch.
Step 3: Update info about remote branches
Clean up stale remote branches that have already been removed. They will be mark as [gone].
Step 4: Clean up ‘gone’ branches
Remove branches marked as [gone]
git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D
Bonus: Remove local (unstaged) changes
Remove any uncommited or untracked leftovers from your local repository.
Squash commits
Step 1: Get an overview of last commits
Step 2: Start rebasing
git rebase -i HEAD~<number-of-commits>
e.g. git rebase -i HEAD~2 for 2 last commits. This works only if there is nothing unstaged on the branch
Step 3: Choose the commits you want to squash to the previous commit
pick commit <commit-id>
squash commit <commit-id>
Adapt and remove 2nd commit message
Save it
Step 4: Force push your rebase to the branch
git push origin <branch-name> -f
# e.g.
git push origin 113-add-supported-hypervisor -f
That’s it.
Git configuration
Ideally sign commits to GitLab. Define your gpg ID.
git config --global user.name "Vorname Nachname"
git config --global user.email "[email protected]"
git config --global user.signingkey <gpg-key-id>
git config --global commit.gpgsign true