Rebase the same branch from origin (git rebase origin/<same?>)

1.8k views Asked by At

I'm on the local dev branch and want to rebase from the same branch on origin. This currently works:

git rebase origin/dev

Is there a way to avoid specifying /dev? Like

git rebase origin/<same>

This would just be to avoid rebasing the wrong branch by mistake and to create a reusable command.

2

There are 2 answers

0
fregante On BEST ANSWER

This does what I want:

git rebase origin/$(git rev-parse --abbrev-ref HEAD)

If there's anything shorter, please suggest.


Slightly unrelated, but I needed this to easily fetch+rebase+push as suggested on Don't Be Scared of git rebase by making it a single command: https://gist.github.com/bfred-it/36e50e20e7927b052372

2
mkasberg On

From the documentation, if upstream is not specified, the upstream branch configured by the branch.name.remote and branch.name.merge options will be used.

If your upstream branch info isn't set correctly, you'll probably need to do git branch --set-upstream-to origin/dev. After that's set up correctly, git rebase should just work.