This is a quick tip I learned recently and it allowed me to improve my git
workflow a bit more.
Hereβs a new part of my .gitconfig
:
[alias]
main = !git checkout main && git pull --no-tags
sync = !git main && git switch -
fuse = !git sync && git rebase main
This week I added these three alias to my .gitconfig
but, if you notice, they are not βregularβ alias. The !
at their beginning tells Git that these are not alias to Git commands, but rather bash commands.
This gives you a simple but powerful way to chain executions, so I created three related alias that I can call depending on my goal:
- If I finished working on a branch and I want to get back to
main
and start with the most recent codebase, Iβll rungit main
. Notice the--no-tags
, this is motivated by working on a large monorepo and not needing all the tags of the packages we keep updating; - If Iβm working on a branch and I want to quickly get any changes made to our
main
branch but come back to the branch Iβm in right now, Iβll callgit sync
. As a note,git switch -
gets you back to the branch you were before you moved to the current branch you are now; - Finally, if I want to bring the current branch Iβm at up to speed with the latest code weβve shipped, Iβll use
git fuse
. It will do everything I described on the other commands so far and rebase ourmain
branch onto the current branch Iβm at.
Cover image by @yancymin
Top comments (0)