Git CheatSheet

28 Mar 2019

Branches

Settings

Set username:

git config --global user.name "MyName" # global settings
git config --local user.name "My Name" # just for the current repository

Set mail address:

git config --global user.email "my@mail.address"
git config --local user.email "my@mail.address"

Rename local branch

If you are on the branch

git branch -m new-name

If you are on a different branch

git branch -m old-name new-name

Rename remote branch

git push origin :old-name new-name

Reset upstream branch

git push origin -u new-name

Delete a remote branch

git push origin :branch-name

Merges

Multiple sign-off

Sign off all single commits from a branch and cherry-pick them to the master branch

git cherry -v master BRANCH-YOU-LIKE-TO-MERGE | cut -f2 -d ' ' | while read LINE; do git cherry-pick -s ${LINE}; done