问题
I've cloned a public GitHub repo [remote origin] for a class I'm taking and pull my assignments from it. After I do the assignments I'd like to push my work to a private BitBucket repo [remote bitbucket] which I created with the commands (fake repo name):
$ git remote add bitbucket https://neilostrove@bitbucket.org/neilostrove/bb-repo.git
$ git push -u bitbucket --all
Password:
Counting objects: 2856, done.
...
Branch master set up to track remote branch master from bitbucket.
Branch work set up to track remote branch work from bitbucket.
$ git push -u bitbucket --tags
Password:
Everything up-to-date
$
Now when I try to pull from origin I get the message:
$ git pull origin
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
I would like to set things up so that when I pull (or fetch) my repo gets updated from origin, and when I push everything is pushed to bitbucket. How can I do that?
This is how I have my remotes set up:
$ git remote -v
bitbucket https://neilostrove@bitbucket.org/neilostrove/bb-repo.git (fetch)
bitbucket https://neilostrove@bitbucket.org/neilostrove/bb-repo.git (push)
origin https://github.com/instructor/gh-repo.git (fetch)
origin https://github.com/instructor/gh-repo.git (push)
回答1:
This use is common enough there's a config item:
git config remote.branch.pushurl u://r/l
Documentation at the git-config(1) Manual Page and git-push(1) Manual Page.
来源:https://stackoverflow.com/questions/24814084/how-do-i-configure-git-to-pull-from-one-repo-and-push-to-another