If I'm working on a branch and then realize I need to merge another branch into mine here is my current workflow (for this example lets say that I'm working on my-branch and want to merge in master):
git stash git checkout master git pull git checkout my-branch git merge master git stash pop
Is there a way in git to pull a branch other than the currently checked out one, or is there a better way to do this?
For example, here's what I'd like to be able to do (again lets say I'm on my-branch and want to merge in master
):
git pull master git merge master
The git-pull man page says that a git pull is just a get fetch followed by a git merge, so is there a way to do the merge part of the git pull on a branch other than the one that's currently checked out?
Or is what I'm asking for just not possible?
If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.
You could use git checkout from the branch you want to transfer the changes to: git checkout <branch name> . That will change all files to match the version in the desired branch. Then you can commit, change, discard whatever you want.
I found an incantation that worked for me:
git fetch origin master:master
then (if you want to merge right away):
git merge master
I was really surprised how hard it was to find an answer to this since it seems like it would be a common use case.
Try this:
git pull yourRepositoryName master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With