1. 程式人生 > >git報錯摘要

git報錯摘要

git報錯摘要

1、在本地電腦上新建了一個分支,程式碼寫完之後,新關聯遠端程式碼庫並提交程式碼:

git init
git add .
git commit -m "標註釋"
git remote add origin https://gitee.com/fangfu/xxxx.git

2、在執行到git push的時候報了個錯:

git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

這個意思是說沒有和遠端庫相關聯。
按照提示,推送當前分支並將遠端設定為上游,執行git push --set-upstream origin master

3、這裡第一次執行的時候,會彈出輸入使用者名稱密碼的對話方塊。如果密碼輸錯了,會報下面這個錯誤:

git push --set-upstream origin master
remote: Incorrect username or password ( access token )
fatal: Authentication failed for 'https://gitee.com/fangfu/xxxx.git/'

而且再次執行,不會彈出之前的對話方塊了。
這裡需要改windows的憑據:
我是win10系統。點選開始–設定,出現windows設定,直接搜尋“憑據管理器”,
在這裡插入圖片描述

選擇windows憑據 :
在這裡插入圖片描述

找到普通憑據–編輯剛剛生成的git:https://gitee.com的憑據,修改使用者密碼就可以了。
在這裡插入圖片描述

4、如果執行git push過程中出現如下錯誤:

git push --set-upstream origin master
To https://gitee.com/fangfu/xxxx.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/fangfu/xxxx.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.

大概是說,本地和遠端的檔案要先合併以後,才能上傳新的檔案,
所以我們需要先把遠端的拉下來

git pull origin master

5、如果在執行git pull中報下面的這個錯誤:

git pull origin master
From https://gitee.com/fangfu/xxxx
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

就表示這是兩個不同的專案,無法合併,
如果要合併,需要新增一行程式碼:–allow-unrelated-histories:

git pull origin master --allow-unrelated-histories