I have two remote repositories: a main repository and a fork, and want to pull new changes from the main repo and push to my fork so I can create pull-requests to the main repo.
I know it is posible to add both remotes using git remote add <name> <url>
but I don't want to explicitly do git pull <main_repo>
and git push <fork_repo>
git remote set-url --push origin <fork_repo>
After doing that you can check urls with this command
git remote -v
and you'll see something like
origin <main_repo> (fetch)
origin <fork_repo> (push)
The solution for this is to add the main repository as the "origin" remote:
git remote add origin <main_repository_url>
Or if already exists:
git remote set-url origin <main_repository_url>
Then set the fork as the push url of the remote:
git remote set-url --push origin <fork_repository_url>
Just to check the results:
$ git remote -v
origin <main_repository_url> (fetch)
origin <fork_repository_url> (push)
And now it is possible to pull/checkout branches from the main repository and push changes to the fork.
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.