Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: pull --rebase without fetching

Tags:

git

When I go to a branch I usually use git pull --rebase which will do a fetch from remote and then will rebase my commits on to the fetched branch. Which is fine. I like it very much because it keeps the history simple and linear.

There are situations where I know I don't want to fetch, because I just did it one minute ago. And me making a bad assumption of this has a very little impact. My fetch is very slow (approximately 20 seconds) because of the repository size. So I want to avoid it.

Let's call the branch in question MyBranch

Thing that works but I consider it being error prone:

$ git rebase orign/MyBranch

I think it is error prone because I have to remember and type in (with the help of auto completion) the name of the current branch. Compared to my intent this is just an opportunity to make mistakes.

I could write a shell script that determines the name of the current branch and then issues this command properly. But I wouldn't do it if there were a simpler solution.

So it would be ideal if I could have a git pull --rebase --no-fetch functionality without making helper scripts.

like image 809
Notinlist Avatar asked Dec 19 '25 21:12

Notinlist


1 Answers

TL;DR
See jonrsharpe's comment and flyingdutchman's answer for a way simpler solution: this is the default behaviour of git rebase without any argument.


Original answer (unnecessary complex) below:

To avoid the typing/error prone aspect, maybe just use the shortcut for current branch's remote counterpart :

git rebase @{u}

If your currently checked out MyBranch branch is set to track origin/MyBranch, this will be equivalent to typing git rebase origin/MyBranch.


Even faster, set an alias : (here ru for "Rebase on Upstream", but choose any name you prefer)

git config alias.ru 'rebase @{u}'

# then
git ru
like image 151
Romain Valeri Avatar answered Dec 22 '25 17:12

Romain Valeri