2016-06-08 71 views
1

我有一個項目,我從公共回購克隆到我調整並推送到Heroku的PC上。
我現在希望將我調整過的代碼作爲備份推送到BitBucket。Git來源於bitbucket

$ git status 
On branch master 
Your branch is ahead of 'origin/master' by 13 commits. 
    (use "git push" to publish your local commits) 

nothing to commit, working directory clean 

$ git remote 
heroku 
origin 

當我嘗試用加到位桶的命令,它的錯誤:

fatal: remote origin already exists 

也就是說,後:

$ git remote add origin [email protected]:me/myproject.git 
$ git push -u origin --all # pushes up the repo and its refs for the first time 
$ git push origin --tags # pushes up any tags 

我會糾正以爲我只需要更新「origin 「指向BitBucket而不是原始的回購?

回答

1

Would I correct in thinking I just have to update "origin" to point to BitBucket instead of the original repo?

作爲備份更直觀只需添加一個新的遠程

git remote add bitbucket /url/to/your/bitbucket/repo 
git push -u bitbucket --all 

如果你真的想改變遠程「origin」(因爲「heroku」就足夠了),那麼它會得到:

git remote set-url origin /url/to/your/bitbucket/repo 

不需要一個git分支命令,push會爲你創建bitbucket遠程分支。

0

因此,您不想再次使用相同的名稱添加遠程設備,該設備將始終失敗。 origin作爲一個名稱除了它是約定外沒有任何內在特殊之處。

您的當前分支設置爲跟蹤遠程origin/master。如果你想能夠直接推送到你的bitbucket作爲一個新的回購。

你可以添加一些遠程命名的bitbucket非常簡單。

git remote add bucket <repo-url> 

然後你就可以更新當前分支能夠跟蹤鬥主分支

git branch -u bucket/master 

所以,當你運行:

git push 

它會直接把你的改變到位桶。

+0

我添加了我的新遠程,然後嘗試git分支-u桶/主但是收到以下錯誤:「錯誤:請求的上游分支」桶/主「不存在」 – Dercni

+0

好了,因爲分支已不存在,在你第一次推動它之前,沒有什麼可以跟蹤的 –