For example, I'm now in develop
branch, and want to pull remote master to local master, what I do is:
$ git stash
$ git checkout master
$ git pull
$ git checkout develop
$ git merge master
Question 1: How to pull remote master to local master when I in develop
branch?
Question 2: Is it possible to merge remote master to local develop in one command? currently I use 4 commands
In case you are using the Tower Git client, pulling from a remote is very easy: simply drag the remote branch and drop it onto your current HEAD in the sidebar - or click the "Pull" button in the toolbar.
The git pull command is actually a combination of two other commands, git fetch followed by git merge . In the first stage of operation git pull will execute a git fetch scoped to the local branch that HEAD is pointed at. Once the content is downloaded, git pull will enter a merge workflow.
You need to checkout the branch. git pull origin todo-mvvm-databinding will fetch and merge this branch into your local one. Show activity on this post. The above answer works well but I wanted to post with fetch and checkout which works fine as well.
Git already only pulls the current branch. If you have branch set up as a tracking branch, you do not need to specify the remote branch. git branch --set-upstream localbranch reponame/remotebranch will set up the tracking relationship. You then issue git pull [--rebase] and only that branch will be updated.
Answer-1: Your working procedure is ok for question-1
.
$ git fetch
$ git stash
$ git checkout master
$ git pull origin master
$ git checkout develop
$ git stash apply
Answer-2: You can pull origin/master
into your local develop
branch directly.
$ git pull origin master
There are already other good answers to your question 2 (see sajib's). The short answer to question 1 is, "You can't".
However, If I can rephrase your question slightly to: "How can I pull remote master onto master while keeping develop checked out?" then you can use git worktree
to your advantage. It gives you another working tree to do all the normal things you'd do with a working tree.
If you're on the develop branch and want to update master, for example:
git worktree add ../second-repo master
git -C ../second-repo merge origin master
Now master has been updated in your local repo.
To explain the above commands, git worktree
will checkout master into another folder (../second-repo
). The second command will execute git merge origin master
only after virtually changing directories to the new worktree. Note that once you have a worktree set up, there's no need set it up again. You can just keep using the same worktree to update 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