0

I forked from repoA, then others merged their PR into repoA, how do I sync repoA and my forkedOfRepoA?
Is it automatically sync?

I visit forkedOfRepoA I saw a message:

This branch is 37 commits behind repoA:master`

What I should do next?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Nadiely Jade
  • 195
  • 2
  • 9

1 Answers1

1

Assuming you are working in a branch which is not master (as a best practice), you would simply rebase your branch on top of repoA

cd /path/to/my/local/fork/clone
git remote repoA https://github.com/<original>/<repoA>
git fetch repoA
git switch my_working_branch
git rebase repoA/master
git push -f

my issue is I want to sync my forkedRepoA:master with repoA:master

For that, this is easier:

cd /path/to/my/local/fork/clone
git remote repoA https://github.com/<original>/<repoA>
git fetch repoA

git switch master
git pull repoA master
git push

git switch my_working_branch
# resume working
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • isn't it easier just sync my forkedRepoA with repoA? imagine have to rebase everytime I push a new branch. I usually don't have conflict pushing, my issue is I want to sync my forkedRepoA:master with repoA:master – Nadiely Jade Dec 01 '20 at 07:56
  • @NadielyJade Sure, I have edited my answer to address your comment – VonC Dec 01 '20 at 08:07
  • is it better if I setup remote url of repoA instead of needing to repeat those step? Then I'll just do `git pull upstream master` – Nadiely Jade Dec 01 '20 at 08:44
  • @NadielyJade The git remote command is to be done only once. What needs to be repeated is the switch to master, pull and push. – VonC Dec 01 '20 at 08:45
  • hmm I see, why not `git remote add upstream https://github.com//`? – Nadiely Jade Dec 01 '20 at 08:46
  • @NadielyJade Sure, you can name it upstream. I only use repoA because that is the name you mentioned in your question. – VonC Dec 01 '20 at 08:47
  • Out of curiosity, why are we using `git switch` here? – Pytth Dec 02 '20 at 16:22
  • 1
    @Pytth Because git checkout is obsolete and confusing: https://stackoverflow.com/a/57066202/6309 – VonC Dec 02 '20 at 16:24
  • @VonC Super interesting! Thanks for that tidbit. – Pytth Dec 02 '20 at 16:30