There’s too many people on my project. 😅
I’m not complaining, but I did have to rebase
my code to master
a LOT.
And it’s always the same 5 lines (or so), so I wrote myself a little shortcut and transformed it into a git “alias”. 🍰
Here’s the excerpt from my .gitconfig
file:
[alias]
rebaseToMaster = "!f() { git add . && git commit -m wip --allow-empty && git co master && git pull && git reset --hard origin/master && git co - && git rebase -i --autosquash master && git reset HEAD~1; }; f"
(works on my machine 😅)
Step by step explanation:
git add .
- add all changed filesgit commit -m wip --allow-empty
- create a commit with the message “wip” (work in progress), allow empty is added, because sometimes I am in the middle of some work, other times I am notgit co master
- switch to themaster
branchgit pull
- pull the latest changes from the remotemaster
branchgit reset --hard origin/master
- reset the localmaster
branch to the remotemaster
branchgit co -
- switch back to the branch you were on beforegit rebase -i --autosquash master
- rebase your branch to themaster
branchgit reset HEAD~1
- remove the temporary commit you made in step 2- 🎉
Now I can be in the middle of a taking apart the whole application and can still rebase
to master
quickly and nonchalantly.