git筆記十:本地倉庫同步到gitlab


本地倉庫同步到gitlab

幫助文檔

git remote --help

操作場景:

  • 本地創建git倉庫(含有readme.md文件), commit了三次
  • gitlab網站創建了一個項目 添加了readme.md 文件
  • 再本地添加 遠程關聯
  • push到gitlab

1:添加遠程分支的關聯

git remote  add  gitlab    git@git.demo123.com:dotnet/basics/gitstudy.git

2: 拉取到本地來吧

git fetch  gitlab
  1. 因為本地和遠程的readme.md 文件沒有做合並, 我們現在來 merge一下
soaeon@DESKTOP-FUJJTHR MINGW64 /f/gitstudy (master)
$ git merge gitlab/master
fatal: refusing to merge unrelated histories

  1. 將兩個不相干的文件 merge一下
soaeon@DESKTOP-FUJJTHR MINGW64 /f/gitstudy (master)
$  git merge     --allow-unrelated-histories     gitlab/master

結果如下:

Merge remote-tracking branch 'gitlab/master'

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
F:/gitstudy/.git/MERGE_MSG [unix] (00:17 23/05/2019)                    1,1 全部
"F:/gitstudy/.git/MERGE_MSG" [unix] 7L, 272C

我們不做任何更改, 直接esc : wq 保存一下即可

merge的結果如下:

soaeon@DESKTOP-FUJJTHR MINGW64 /f/gitstudy (master)
$  git merge     --allow-unrelated-histories     gitlab/master
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

執行gitk 查看一下分支圖

soaeon@DESKTOP-FUJJTHR MINGW64 /f/gitstudy (master)
$ gitk
  1. 推送到遠端
git push gilab  master

git push的一般形式為 git push <遠程主機名> <本地分支名> <遠程分支名> ,例如 git push origin master:refs/for/master ,即是將本地的master分支推送到遠程主機origin上的對應master分支, origin 是遠程主機名,

​ 第一個master是本地分支名,第二個master是遠程分支名。

關於本地分支推送到遠程分支

推送本地分支local_branch到遠程分支 remote_branch並建立關聯關系(origin 是git 倉庫url的簡稱)

a.遠程已有remote_branch分支並且已經關聯本地分支local_branch且本地已經切換到local_branch

git push

b.遠程已有remote_branch分支但未關聯本地分支local_branch且本地已經切換到local_branch

git push -u origin/remote_branch

c.遠程沒有有remote_branch分支並,本地已經切換到local_branch

git push origin local_branch:remote_branch


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM