git 创建分支命令行

1:git branch branchName(在本地创建一个命名为branchName的分支)

2:git branch 查看当前自己所在的分支

3:git branch -a 查看服务器的所有分支以及自己当前所在的分支

4:git push origin branchName(把命名为branchName的本地分支推送到服务器)

5:git checkout --track origin/branchName (切换为远程服务器上的命名为branchName的远程分支)

6:如果你的搭档要把他本地的分支给关联到服务器上命名为branchName的远程分支,请执行以下操作,git branch --set-upstream localBranchName origin/branchName  (为本地分支添加一个对应的远程分支 与之相对应)->这行命令用来关联本地的分支与服务器上的分支

7:完成以上操作之后,就可以进行提交代码了,但是在提交代码之前,你要确定你当前所在的分支

8:git push origin branchName(提交代码到远程服务器上命名为branchName的分支上)

9 :git pull origin branchName (从远程分支上拉取代码)


扫描二维码关注公众号,回复: 2414509 查看本文章

1、查看本地分支:

[html]  view plain  copy
  1. $ git branch  
  2.   master  
  3. * mutilrecall  

 查看远程分支:

[html]  view plain  copy
  1. $ git branch -a  
  2.   master  
  3. * mutilrecall  
  4.   remotes/origin/master  
  5.   remotes/origin/mutilrecall  
注:其中,remotes开头的代表是远程分支。


2、创建本地分支,并切换到分支:

[html]  view plain  copy
  1. $ git branch test  
  2.   
  3. kevinliu@TP-A1116-L MINGW64 /e/workspace_ttengine/ttengine (mutilrecall)  
  4. $ git checkout test  
  5. Switched to branch 'test'  

3、本地分支关联远程分支:

在本地test分支上修改了代码后,需要提交到远程,这时就需要关联远程的某个远程分支,操作如下:

1)本地提交:

[html]  view plain  copy
  1. git gui  


2)push到远程

[html]  view plain  copy
  1. $ git push origin test:test  
  2. Counting objects: 15, done.  
  3. Delta compression using up to 4 threads.  
  4. Compressing objects: 100% (9/9), done.  
  5. Writing objects: 100% (15/15), 927 bytes | 0 bytes/s, done.  
  6. Total 15 (delta 7), reused 7 (delta 0)  
  7. remote:  
  8. remote: Create merge request for test:  
  9. remote:   http://gitlab.avc.domain/ttengine/ttengine/merge_requests/new?merge_request%5Bsource_branch%5D=test  
  10. remote:  
  11. To http://gitlab.avc.domain/ttengine/ttengine.git  
  12.  * [new branch]      test -> test  

:第一次无法pull,只能push

注:如果不写远程分支名称,则默认和本地分支同名,这时命令为:$ git push origin test


3)从远程pull:

[html]  view plain  copy
  1. $ git pull origin test:test  
  2. Already up-to-date.  

注:如果不写本地分支名称,则默认和远程分支同名,这时命令为:$ git pull origin test:

3、从远程分支上下代码:

[html]  view plain  copy
  1. $ git clone -b mutilrecall http://gitlab.avc.domain/ttengine/ttengine.git  

clone远程仓库到制定目录:

[html]  view plain  copy
  1. git clone xxx.git "指定目录"  

猜你喜欢

转载自blog.csdn.net/u012845099/article/details/80225542