2018年5月10日 星期四

bitbucket.org git免費教學

說明文 : https://ithelp.ithome.com.tw/articles/10156944
說明push失敗:https://stackoverflow.com/questions/38255655/trying-to-pull-files-from-my-github-repository-refusing-to-merge-unrelated-his

在bitbucket 申請完免費帳號後, 如果當初申請帳號,是使用第三方登入googel等,需要到setting設定你的密碼  。

->setting ->connect accounts ->connect github


連結完成後,就可以使用github帳號登入。

在本地電腦。

1. git init

2. git remote add origin 網址

3. git pull origin master --allow-unrelated-histories

4. 編輯vim ,ESC跳出,在底下打w 存檔,最後用q離開編輯頁面回到指令\。

5. git commit -m "first"

6. git pull origin master

7. git push origin master  應該就可以成功。

備註會有錯誤產生原因可能是因為:
repo上面已經有一個 readme檔案,導致衝突
顯示以下訊息:! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/******/*****.git
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
但又遇到問題了,error message如下:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/*****/*****.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.
輸入git pull origin master就解決了。 而會發生以上問題的原因,是因為有local branch 和 origin branch的問題。

沒有留言:

張貼留言