2

I am working on a feature branch, my master branch is set up to track origin/master. I want to pull changes into master from origin/master that have been merged in without having to switch to master from my feature branch. How would I do that?

Jasonca1
  • 4,848
  • 6
  • 25
  • 42

2 Answers2

1

I don't believe that there is such an option honestly for pull, since it's a git fetch and a git merge one after the other. But what you can do is create a git alias that will do it for you.

You can put this into your global (or local) gitconfig

[alias]
    pull-into = "!p() { git checkout $1 && git pull --rebase && git checkout - ; }; p"

This will create a git pull-into alias, where it just defines a bash function called p. You pass to it the branch you want to pull from. It goes to it, pull --rebase's it on it (or you can just have git pull if you just need that) and then goes back to your previous branch.

You can invoke it like so and it will give such an output

# currently on branch featurex
git pull-into master

Switched to branch 'master'
Your branch is behind 'origin/master' by X commits, and can be fast-forwarded.
  (use "git pull" to update your local branch) 
Updating 7699151..23b27bf
Fast-forward
<CHANGES AND SO ON>
Current branch master is up to date.
Switched to branch 'featurek'
Your branch is up to date with 'origin/featurex'.
mnestorov
  • 4,116
  • 2
  • 14
  • 24
0

Are you sure you need to do that? A more common desire is to update your branch from the current remote state of master. And that is something you can readily do without leaving your branch:

  1. fetch to update all remote-tracking branches, including origin/master

  2. merge origin/master (into your current branch) — actually I prefer to rebase, it's up to you

Now the remote state of master is part of your branch, and the differences are thus minimized. That is most likely your actual goal.

matt
  • 515,959
  • 87
  • 875
  • 1,141