June 26, 2021
Quickly pull on a different branch using git
Finding the easiest way to pull updates from main into feature branch
It's something I've always taken for granted. When updating the main branch when working from a feature branch, I had to issue the following commands:
git checkout maingit pull origin maingit checkout -git merge main
It becomes even worse when having local changes that you're not ready to commit just yet. In which case the commands are:
git stashgit checkout maingit pullgit checkout -git merge maingit stash pop
I usually work in Visual Studio and when doing this; on each step the IDE has to reload the solution and all projects within, and because the code between the branches will most likely change, it also has to parse all the codefiles. Needless to say this is cumbersome and slow.
Until at one time I started looking for an alternative to this problem. I came across this stackoverflow question, but the answer was not really obvious from the replies. So here is the thing I was looking for exactly.
git pull origin main:main
Additionally if you also want to merge the latest changes into the branch you're working on do the following;
git merge main
Today I learned something new!