fregante
fregante

Reputation: 31779

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

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.

Upvotes: 2

Views: 1914

Answers (2)

fregante
fregante

Reputation: 31779

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

Upvotes: 1

mkasberg
mkasberg

Reputation: 17342

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.

Upvotes: 2

Related Questions