2017-04-20 86 views
1

我是新手混帳。我在bitbucket上有一個倉庫。現在我想在工作中將其下載到計算機上,並對項目進行一些更改,然後重新推送。如何在新計算機上同步我的git存儲庫?

首先我初始化上的本地目錄混帳通過這條線:

$ git init 

然後我設置一些配置:

$ git config --global user.name "my name" 
$ git config --global user.email [email protected] 

然後我下載這樣的:

現在我可以在我的本地文件夾中看到項目的文件。好,好!

而且我做了這個命令我的倉庫,我的本地目錄之間的連接:

$ git remote add origin https://[email protected]/ ... 

現在,當我進入$ git remove -v,結果將是:

origin https://[email protected]/ ... (fetch) 
origin https://[email protected]/ ... (push) 

似乎不錯!


當我輸入以下命令:git status,我會看到紅色的所有文件夾/文件。因爲我輸入了這個命令:

$ git add . 

現在他們是綠色的!我也寫了一本線提交它:

$ git commit -m "there isn't any change" 

然後同步我的本地目錄與到位桶一個,我進入這一行:

$ git push origin master 

但我得到這個錯誤:

$ git push origin master 
To https://bitbucket.org/lamtakam/lamtakam.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to 'https://[email protected]/lamtakam/lamtakam.git' 
hint: Updates were rejected because the tip of your current branch is behind 
hint: its remote counterpart. Integrate the remote changes (e.g. 
hint: 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

怎麼回事,我該如何解決?

回答

1

你的第一步是錯誤的:

git init 

這初始化在當前目錄下一個全新的git倉庫。你不想這樣做,你只想克隆現有的存儲庫。

實際上發生了什麼事是你,然後克隆現有的資源庫您在步驟1初始化嵌套的git倉庫是有點複雜的新資源庫,但底線是,這些文件出現紅色的,因爲所有的文件是新初始化的git repo(這與您在bitbucket中的回購沒有任何關係)。

您當前的目錄樹看起來是這樣的:

/htdocs 
    /New Folder <--- you initialized the new git repo here 
    /lamkatam <--- this is the git repo you cloned 

跳過第一步,這樣做只是git clone重新開始(你可能要爲此在htdocs文件夾)。您也可以跳過設置遙控器 - 當您進行克隆時,它會自動設置名爲origin的遙控器並對其進行正確配置。

0

一切都OK了,在此期間,有人更新了資料庫,推前您需要整合您的更改:

git pull 

這似乎是對遠程倉庫的變化可能需要一些在你身邊「合併」 。如果這是真的,你應該改變你的副本,並提交這些更改,然後執行:

git push 

如果在此期間沒有人並未改變原點庫,你應該能夠把你的變化。

+0

它不起作用https://i.stack.imgur.com/1TfMV.png – stack

+0

你確定你在主分支? (git狀態輸出) –

+0

https://i.stack.imgur.com/vHfB7.png – stack

0

hint: Updates were rejected because the tip of your current branch is behind

您需要先(同步帶遙控)更新本地資源庫,然後推到遠程(origin)。

$ git pull origin master 
$ git push -u origin master 
+0

不幸的是'拉'不工作https://i.stack.imgur.com/1TfMV.png – stack

+0

嘗試'git pull -u origin master'而不是'git pull'。 –

+0

仍然'推'不工作https://i.stack.imgur.com/g0Xa9.png – stack

相關問題