Working with multiple remotes in git

I am working on a new project and would like to start with the seed project I found on GitHub.
I cloned the seed project locally, now it shows 1 remote branch when I execute the command:

git remote -v

However, I would like to add a new pool to this repo and make all my changes or change the source code of this new repo, which is a private repo.

After adding a new remote, now I can see 2 remotes in the repo.

How can I switch between two remotes?
I don’t think that commands like this git checkoutwill work when working with two branches from two different remotes.

+4
source share
2 answers

"", , :

git push origin
# or
git push remote2

, .

( ) push url:

git remote set-url --push origin user@example.com:repo.git

, , git checkout, .

git checkout .
:

git checkout -b abranch remote2/abranch

, , , . .

:

enter image description here

origin, , .

$ git remote add upstream https://github.com/atom/atom
$ git fetch upstream

origin/abranch, /abranch, , .

git checkout -b abranch origin/abranch
git rebase upstream/abranch
git push --force
+6

, .

git clone -o upstream user@example.com:upstream.git
cd upstream
git branch -m upmaster
git checkout -b master
git remote add origin user@example.com:myrepo.git
git push -u origin master

, .

, .

git checkout upmaster
git pull
git checkout master
git rebase upmaster
0

All Articles