[{TableOfContents}]

This is for keeping your branch up to date and always having a PR / MR with only one commit.  It is helpful if you use Oh-My-Zsh.

!!! Squashing Your Branch

|| Description || Zsh || Git
| Checkout branch | {{{gco $branch_name}}} | {{{git checkout $branch_name}}}
| Squash against master | {{{g rbim}}}[1] | {{{git rebase -i HEAD~$(git rev-list --count master..);
}}}
| Squash against another branch | {{{g rbi <branch>}}}[2] | {{{git rebase -i HEAD~$(git rev-list --count ${1}..);
}}}
| Force push your branch | {{{ggfl}}} | {{{git push 
--force-with-lease 
origin $current_branch}}}

[#1] {{{rbi = "!f() { git rebase -i HEAD~$(git rev-list --count master..); }; f"}}}

[#2] {{{rbi = "!f() { git rebase -i HEAD~$(git rev-list --count ${1}..); }; f"}}}

[#3] {{$Y}} is displayed in GitLab at the top, where it says ''Overview: X, Commits: Y, Pipelines: Z, ...'' . The number you want is Y.

!!! Update From Master

Time passes, commits get merged to master. You need to update your branch.

Assuming you are currently in {{$branch_name}},

|| Description || Zsh || Git
| Checkout master | {{{gcm}}} | {{{git checkout master}}}
| Pull | {{{gl}}} | {{{git pull}}}
| Checkout branch | {{{gco @{-1} }}}[3] | {{{git checkout @{-1} }}}
| Rebase from master | {{{grbm}}} | {{{git rebase master}}}
| Handle conflicts, test, etc.
| Force push {{{$current_branch}}} to remote | {{{ggfl}}} | {{{git push 
--force-with-lease 
origin $current_branch}}}

[#3] references the most recent branch, {{{$branch_name}}}

!!! Push to Master

Checkout master, merge feature branch into master, push master

|| Description || Zsh || Git
| Checkout master | {{{gcm}}} | {{{git checkout master}}}
| Merge feature branch into master | {{{gm $feature_branch}}} | {{{git merge $feature_branch}}}
| Push master| {{{ggp}}} | {{{git push origin master}}}

----
[CategoryComputing.SCM.Git]