我想从GitHub克隆一个开源项目,但我想使用Bitbucket作为我的远程存储库主机,因为它的私有repo是免费的。
我不打算fork / pull request,但当原始项目得到更新时,我想将更新拉到我的本地存储库并合并。
我认为最终我需要两个远程存储库。(origin和upstream?)
设置这样的环境的正确/安全方法是什么?
google-calendar-backup
的私有Git仓库。Clone original repo from GitHub
git clone https://github.com/christianspecht/google-calendar-backup C:\LocalDir
This will create a remote "origin" in the local repo which points to GitHub.
Since you want to work mainly with Bitbucket, Bitbucket should be the "main" remote origin
, so we'll rename the existing one.
cd c:\localdir
git remote rename origin upstream
Go to local dir and add the Bitbucket repo as a second remote:
git remote add origin https://bitbucket.org/christianspecht/google-calendar-backup
(optional) Show both remotes:
git remote -v
On my machine, I get this result:
origin https://bitbucket.org/christianspecht/google-calendar-backup (fetch)
origin https://bitbucket.org/christianspecht/google-calendar-backup (push)
upstream https://github.com/christianspecht/google-calendar-backup (fetch)
upstream https://github.com/christianspecht/google-calendar-backup (push)
Push all branches to Bitbucket once
git push -u --all origin
Result:
Username for 'https://bitbucket.org': christianspecht
Password for 'https://christianspecht@bitbucket.org':
Counting objects: 30, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (30/30), done.
Writing objects: 100% (30/30), 4.41 KiB | 0 bytes/s, done.
Total 30 (delta 12), reused 0 (delta 0)
To https://bitbucket.org/christianspecht/google-calendar-backup
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
(Credit to larsks for -u
- I didn't know this, I'm still learning Git myself)
就是这样。现在你可以进行修改并将其推送到 origin
(Bitbucket)。
有时候,你需要从 upstream
(GitHub) 拉取以获取原始项目的新更改。
origin
和upstream
这些名称在这种设置中非常典型。第一次推送分支时,请确保使用-u
设置正确的远程跟踪分支。 - larsks