2

So I am in branch feature. And I want to rebase w/ branch master.

git rebase master

And it says that feature branch is up-to-date. Of course it is because master branch hasn't changed — it is the same as in moment when I create feature branch from it.

Actually it is not. All I need is to do pull in master branch.

git checkout master
git pull
git checkout feature

My question: can't I update master branch w/o checking-out to it?

I tried from feature branch:

git pull origin master master

...but it updated feature branch (not what I wanted to) and it has commits “in furure“ in it.

Thanks in any advice! :)

Zoe
  • 27,060
  • 21
  • 118
  • 148
daGrevis
  • 21,014
  • 37
  • 100
  • 139
  • possible duplicate of [git: update a local branch without checking it out?](http://stackoverflow.com/questions/3216360/git-update-a-local-branch-without-checking-it-out) –  Apr 03 '14 at 21:07

2 Answers2

5

If you are sure that you don't have anything on master that you want to keep you can do:

git fetch
git update-ref refs/heads/master origin/master

If you are doing this regularly, though, there is really no point in keeping your master branch. Just use the remote tracking branch (origin/master) for merges, diffs, rebases, etc. as it is updated automatically by git fetch.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • I think you didn't understand my question — I need `master` branch and it's updated all the time. My question: How to checkout-pull-checkout w/ one command? – daGrevis Nov 27 '12 at 09:07
  • @daGrevis: So you have commits on master that aren't pushed to the origin repository? – CB Bailey Nov 27 '12 at 09:10
  • No. I have `master` branch that has new commits in origin, but they are not pulled. To rebase, I need to pull first. – daGrevis Nov 27 '12 at 09:18
  • 3
    @daGrevis: So why don't you just rebase against `origin/master`? There's no point in updating a local branch if you're not actually going to check it out and work on it. – CB Bailey Nov 27 '12 at 09:20
  • That's what I wanted! Thanks. – daGrevis Nov 27 '12 at 09:28
  • +1 for understanding the question and giving two correct answers :) – joeytwiddle Jan 04 '14 at 08:21
2
git push . origin/master:master

the dot refers to the current repository. This will stop you from doing non-fast-forward updates. If you still want to that, you can add the -f or --force options.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • This gets my vote because I was specifically looking for something that would prevent non-fast-forward updates. Bonus that it uses a porcelain command. The additional info about dot makes this perfectly clear for users already familiar with push. – laindir May 17 '16 at 15:04
  • Trying this while on a feature branch. I *think* this worked sometime in the past, but from some reason, `master` is not being updated. How should I debug this? – ysap Mar 29 '17 at 16:14