1. 程式人生 > >git push 原因以及問題!

git push 原因以及問題!

$ git push ssh://[email protected]/rt4ls.git master // 把本地倉庫提交到遠端倉庫的master分支中

$ git remote add origin ssh://[email protected]/rt4ls.git
$ git push origin master 


這兩個操作是等價的,第二個操作的第一行的意思是新增一個標記,讓origin指向ssh://[email protected]/rt4ls.git,也就是說你操 作origin的時候,實際上就是在操作ssh://[email protected]/rt4ls.git。origin在這裡完全可以理解為後者 的別名。


    注意:需要說明的是,預設情況下這條語句等價於提交本地的master倉庫到遠端倉庫,並作為遠端的master分支。
    如果想把本地的某個分支test提交到遠端倉庫,並作為遠端倉庫的master分支,或者作為另外一個名叫test的分支,那麼可以這麼做。

$ git push origin test:master         // 提交本地test分支作為遠端的master分支
$ git push origin test:test              // 提交本地test分支作為遠端的test分支

如果想刪除遠端的分支呢?類似於上面,如果:左邊的分支為空,那麼將刪除:右邊的遠端的分支

當要push程式碼到git時,出現提示:

error:failed to push some refs to ...

Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:

  1. $ git push origin master  
  2. To ../remote/  
  3.  ! [rejected]        master -> master (non-fast forward)  
  4. error: failed to push some refs to '../remote/'  
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.
This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.


問題(Non-fast-forward)的出現原因在於:git倉庫中已經有一部分程式碼,所以它不允許你直接把你的程式碼覆蓋上去。於是你有2個選擇方式:

1,強推,即利用強覆蓋方式用你本地的程式碼替代git倉庫內的內容

git push -f

2,先把git的東西fetch到你本地然後merge後再push

$ git fetch

$ git merge

這2句命令等價於
  1. $ git pull  

可是,這時候又出現瞭如下的問題:


上面出現的 [branch "master"]是需要明確(.git/config)如下的內容
[branch "master"]
    remote = origin

    merge = refs/heads/master

這等於告訴git2件事:

1,當你處於master branch, 預設的remote就是origin。

2,當你在master branch上使用git pull時,沒有指定remote和branch,那麼git就會採用預設的remote(也就是origin)來merge在master branch上所有的改變

如果不想或者不會編輯config檔案的話,可以在bush上輸入如下命令列:

  1. $ git config branch.master.remote origin  
  2. $ git config branch.master.merge refs/heads/master  

之後再重新git pull下。最後git push你的程式碼吧。it works now~


$ git push origin :test              // 剛提交到遠端的test將被刪除,但是本地還會儲存的,不用擔心。

相關推薦

git push 原因以及問題

$ git push ssh://[email protected]/rt4ls.git master // 把本地倉庫提交到遠端倉庫的master分支中 $ git remote add origin ssh://[email protected]/r

git常見錯誤git push rejected的原因

之前對git的使用很不熟練,在前幾天重新學習了之後,測試時提交報了錯: ![rejected] master->master(fetch first) error:failed to push some refs to 'https://github.com/xxx

Git push 失敗原因總結

hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another reposi

git push.default設置

ted csdn 老版本 specified 相同 def nbsp 8.4 cto 轉自:http://blog.csdn.net/daijingxin/article/details/51326715 在進行一次空倉庫的提交時,我遇到了這個警告 警告如下:

Git總結筆記4-git push origin master 報錯的解決方法

failed 總結筆記 rebase nbsp read hint err ont version 1 錯誤提示如下: 2 [[email protected]/* */ php]# git push -u origin master 3 To [ema

02_創建Git倉庫,克隆倉庫,git add,git commit,git push,git pull,同行沖突,不同行沖突的結局方案,git mergetool的使用

round rom weight art sdn automatic remote then config 1 創建Git資源庫,殘酷文件夾信息 創建git資源庫的命令: git init –bare 倉庫名稱 (當中-bare表示的意思是空的庫的意思)

內存溢出和內存泄漏的區別、產生原因以及解決方案 轉

服務 har 操作 ger 遞歸調用 問題 let share 查錯 內存溢出 out of memory,是指程序在申請內存時,沒有足夠的內存空間供其使用,出現out of memory;比如申請了一個integer,但給它存了long才能存下的數,那就是內存溢出。 內

git push前怎樣遺棄掉歷史commit

mit 拷貝 easy 下載 性能 water repos 無法 ont 今天寫了一天代碼,然後 git hub commit 了 多達 7 次。 可是都沒有把改動正式推送上去。結果最後要推送的時候發現中間有一個提交文件超過了100M. 是 vs 的代碼性能分析報告 .

兒童學編程的原因以及方法

運動 嘗試 工具 編碼 多個 col ffffff wid ack 無論你的孩子在長大後能否成為下一個紮克伯格,編程對他或者她來說都是一個非常有用的技能。它會幫助你的孩子提高解決問題的能力、創造力和溝通能力。同時,這對你來說也是一種樂趣。這裏有一些經過檢驗的優秀的應用程序,

git push提交時卡住

卡住 提交 oba ack windows span class send oca windows可能會有這個問題, 需要設置 git config --global sendpack.sideband false 和 git config --local sendp

js ==和===以及= 和 ==的區別

true style cnblogs 基礎類型 family var ber 16px 運算 一、js == 與 === 的區別[轉] 1. 對於string,number等基礎類型,==和===是有區別的   1)不同類型間比較,==之比較“轉化成同一類型後的值”看“

CentOS7——gitlab本地git倉庫搭建 以及web hook配置

ron pda tran 訪問 visit epo 目前 down style 整個搭建用的都是各種默認設置,所以沒有用到高深的的東西,比較簡單,比較傻瓜式,這篇也僅僅是一個入門。 另外本文具有時效性,瀏覽本文請註意發表時間,為防止過時產生誤導,本文盡量把 “如何得知應該這

git push 失敗

技術 jsb watermark blog img data- ext fill con 先上圖 已經加入了sshkey 為撒ssh 不成功,.push 僅僅能通過http方式,每次都要輸入用戶 password非常麻煩. 蛋碎了幾個月,今天節前最後一個

<問題解決02>Linux虛擬機使用git push報錯--解決方案如下:

hello class lai git onf http afr 再次 log 問題描述:   使用git push 報錯:     error: The requested URL returned error: 403 Forbidden while accessing

git push 沖突

錯誤 -1 images font 兩個 img size 部分 ges 當多人上傳同一項目代碼出現沖突時: 例如: 有一個倉庫Test,兩個同學A和B,分別clone到自己的本地目錄,A同學修改文件file(push到github),B同學也修改了文件file,B同學

內存溢出和內存泄漏的區別,產生原因以及解決方案

解決方案 集合類 釋放內存 分頁 需求 查看內存 取出 程序 tof 一、概念與區別 內存溢出 out of memory,是指程序在申請內存時,沒有足夠的內存空間供其使用,出現out of memory;比如申請 了一個integer,但給它存了long才能存下的數,那就

git —— 基本命令以及操作(No.1)

src del 刪除 blog -1 comm commit 操作 提交 git基本命令(附加描述) 1.把文件添加到暫存區$ git add readme.txt 2.把暫存區的文件文件添加到倉庫$ git commit -m "提交說明" 備註:add添加單個文

git push origin與git push -u origin master的區別

2.0 matching 命令 參數 主機 主機名 bsp 如果 方法 $ git push origin 上面命令表示,將當前分支推送到origin主機的對應分支。 如果當前分支只有一個追蹤分支,那麽主機名都可以省略。 $ git push 如果當前分支與多個主機存在

git push origin master 遇到的分支問題

push 但是 提交 ack tro 使用 原因 str 修改 我從master分支創建了一個issue1分支,做了一些修改後,使用git push origin master提交,但是顯示的結果卻是‘Everything up-to-date‘, 發生問題的原因是git

git push

tortoise 圖片 oschina .cn 比較 快的 center tom nis 確保 gitlab裏項目的members裏有當前user,即有push權限。 http://blog.csdn.net/yanzi1225627/article/details/1