简体   繁体   中英

rebase branch from remote

There is a project on GitHub with 2 branches:

upstream/Master
upstream/stable-v1

I forked the project so now in my private github account I have:

origin/Master
origin/stable-v1

I downloaded the project to my local mac using SSH so now in my mac I have:

Master  origin/Master
stable-v1 origin/stable-v1

To sync my local and origin of master i do:

git checkout master
git fetch --all
git reset --hard upstream/master
git push --force

But this sync only master. I want also to sync stable-v1 the issue is that this branch needs to be synced from upstream/stable-v1 and not from master !

When I do:

git checkout stable-v1
git pull --rebase

it tells me

Already up to date.
Current branch stable-v1 is up to date.

but this is not true I'm 1000+ commits behind.

I also tried to do that using Pycharm VCS options https://www.jetbrains.com/help/pycharm/sync-with-a-remote-repository.html#update-git-branch but nothing works.

I think that it tries to sync my local copy from origin but what I'm trying to do is sync the local copy from upstream and then push it to origin. Or is there a way to sync origin first and then pull it to local? I'm very confused here.

My preferred way of working with remotes is to never use pull , but always use fetch followed by a merge / rebase . pull does the same behind the scenes, but I like to be able to inspect the history before that.

Fetch from all remotes, checkout your branch, rebase your branch:

git fetch --all
git checkout stable-v1
git rebase upstream/stable-v1

rebase generally has the form --onto AB C which takes all commits reachable from C but not from B (one might say "take all commits from B to C", but that is inaccurate) and copy it onto A .

Shorthands exist:

  • rebase --onto AAB == rebase AB
  • rebase A current-branch == rebase A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM