引用https://www.cnblogs.com/u-1596086/p/11588957.html
第一步:登陸git建立項目html
右上角頭像按鈕,點擊your repositoriesgit
接着綠色按鈕:newgithub
接着就是命名,再點擊create respositoory,就在git上建立好了項目。centos
第二步,關聯遠程倉庫ssh
1,建立成功以後,咱們會看到倉庫的地址,以下:git@github.com:lenve/test.git,而後我須要將咱們以前的本地倉庫和這個遠程倉庫進行關聯,使用git remote add命令,以下:gitlab
$ git remote add origin git@github.com:lenve/test.git.net
在這條命令中,git會自動將遠程倉庫的名字設置爲origin,方便咱們的後續操做。orm
2,假設我想將本地master分支上的內容推送到遠程master分支上,方式以下:htm
$ git push -u origin master
若是想推送到其餘分支,仍是這條命令,修改一下分支的名字便可,好比我也想把個人fa分支推送到遠程倉庫中,執行以下命令:blog
$ git checkout fire
$ git push -u origin fire
引用https://blog.csdn.net/sinat_36246371/article/details/79738782(原文連接)
在執行git pull的時候,提示當前branch沒有跟蹤信息:
git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
1
2
3
對於這種狀況有兩種解決辦法,就好比說要操做master吧,一種是直接指定遠程master:
git pull origin master
1
另一種方法就是先指定本地master到遠程的master,而後再去pull:
git branch --set-upstream-to=origin/master master
git pull
1
2
這樣就不會再出現「There is no tracking information for the current branch」這樣的提示了。
引用https://www.centos.bz/2018/03/git-%E5%87%BA%E7%8E%B0-fatal-refusing-to-merge-unrelated-histories-%E9%94%99%E8%AF%AF/
git pull 失敗 ,提示:fatal: refusing to merge unrelated histories
其實這個問題是由於 兩個 根本不相干的 git 庫, 一個是本地庫, 一個是遠端庫, 而後本地要去推送到遠端, 遠端以爲這個本地庫跟本身不相干, 因此告知沒法合併
具體的方法, 一個種方法: 是 從遠端庫拉下來代碼 , 本地要加入的代碼放到遠端庫下載到本地的庫, 而後提交上去 , 由於這樣的話, 你基於的庫就是遠端的庫, 這是一次update了
第二種方法:
使用這個強制的方法
git pull origin master --allow-unrelated-histories
後面加上 --allow-unrelated-histories , 把兩段不相干的 分支進行強行合併
後面再push就能夠了 git push gitlab master:init
gitlab是別名 , 使用
Java代碼
git remote add gitlab ssh://xzh@192.168.1.91:50022/opt/gitrepo/withholdings/WithholdingTransaction
master是本地的branch名字
init是遠端要推送的branch名字
本地必需要先add ,commit完了 才能推上去
關於這個問題,能夠參考http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories。
在進行git pull 時,添加一個可選項
git pull origin master --allow-unrelated-histories