Git提示rejected
To github.com:zhuxiaoxi/Web-Demo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:zhuxiaoxi/Web-Demo.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.
原因
遠端倉庫有一部分程式碼已經被包含不允許直接推送到遠端倉庫
解決方法
- 在推送時,使用
-f
選項,強制推送
git push origin master -f
Git提示remote origin already exists
fatal: remote origin already exists.
原因
已經設定了一個遠端倉庫,無法設定新的
解決方法
- 執行
git remote rm origin
,再修改遠端倉庫git remote add origin git@github.com:zhuxiaoxi/dotfiles.git
Git提示fatal: refusing to merge unrelated histories
git pull origin master
From github.com:zhuxiaoxi/dotfiles
- branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
解決方法
- 在拉取時,使用
--allow-unrelated-histories
選項,忽略無關的歷史
git pull origin master --allow-unrelated-histories
Git提示Please make sure you have the correct access rights
ssh: Could not resolve hostname origin: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解決方法
# git push origin:peppa 錯誤,修改為下面的
git push origin :peppa