Home > Net >  Git: pulling without fetching
Git: pulling without fetching

Time:02-12

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.

CodePudding user response:

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

CodePudding user response:

Sorry, I read the question wrong, you could do:

git rebase origin/HEAD
  •  Tags:  
  • git
  • Related