一)将本地分支连接到远程分支,这里以GitHub上的同名仓库(项目)为例

1)进入本地项目主分支

2)运行以下命令:

#git remote add origin git@github.com:path/repoName.git        //将远程仓库命名为origin

3)当本地仓库与远程仓库都仅有一个主分支时,运行以下命令:

#git push -u origin master        //加参数-u,git不仅会将本地主分支所有内容推送到远程主分支,还会自动将本地主分支与远程主分支连接起来

注:

1)手动建立分支连接命令:

#git branch --set-upstream-to=origin/branchName branchName(local)

2)如果本地仓库有多个分支,则需先手动建立对应分支连接,然后pull,最后再push来实现同步:

#git checkout branchName        //默认master分支

#git branch --set-upstream-to=origin/branchName branchName(local)

#git pull origin branchName --allow-unrelated-histories

#git push

***Master以外其他分支:

#git checkout branchName

#git push --set-upstream origin branchName    //将分支推送至远程端,从而在远程端创建同名的分支

二)克隆远程仓库

1)通过SSH

git clone  git@github.com:TaoismLEE/Git.git

Notes 1:

A. After modifying, use: "git push origin master" to push the modification.

B. Can use: git remote -v to check the information about remote repository.

Notice 2:

If clone using SSH method, the data transfered between Git and Github will be encrypted with SSH key, so some settings should be made firstly in order to fetch the project from Github successfully:

Setting SSH key:

A. In home folder, check whether the .ssh folder exists, if exists,then check whether there are "id_rsa" and "id_rsa.pub" files

B. If the folder or the files not exist, then generate them by running following commands:

#ssh-keygen -t rsa -C "email-address" //configured email of git

C. Setting SSH Key in Github with the content of id_rsa.pub file //Open "Account settings" -> "SSH Keys"; then click "Add SSH Key";fill in "Title"; in the Key textarea, paste the content of id_rsa.pub file

2)通过HTTPS

git clone https://github.com/TaoismLEE/Git.git

or

git clone https://LoginUserName@github.com/TaoismLEE/Git.git

Notice:

If clone using HTTPS method, will need accout and password of remote Github when pushing modification to remote repository. OR running below command to store and remember the remote account information:

#git config --global credential.helper store

3)克隆后获取非主分支

#git checkout -b dev(suggest to name the new local branch the same with the remote branch) origin/dev(other branch in remote repository)

三)协同工作

A. First, try to use "git push origin branch-name" to push our own modification

B. If conflict, then should use "git pull" to pull out the latest code

C. Fix conflicts manually and commit as a new version

D. Run "git push origin branch-name" again to push our code

转载于:https://blog.51cto.com/taoismli/1936951

Git手册 - 分支远程同步相关推荐

  1. git本地分支 远程分支简单操作(后续更新)

    首先注意git命令首先是目标,后接基于的来源(缺省基于当前分支).常用的git分支操作进行总结如下: ref:https://my.oschina.net/iak1001/blog/2878914 查 ...

  2. git切换分支会同步修改的代码问题解决

    最近切换分支的时候发现切换前的分支上的修改的代码会被同步到切换后的分支上,原因就是因为在分支上修改后没有进行commit暂存起来,所以就会带过去,切换分支前先commit一次修改的内容就不会同步到切换 ...

  3. git显示服务器所有分支,git 查看所有远程分支以及同步

    在多台电脑使用git管理开发分支的时候,会出现这样的情况.电脑A创建了分支1,并且push上了远程仓库. 电脑B本地clone仓库默认只会clone下master分支,而其他电脑A推送的分支是不会默认 ...

  4. git 拉取远程其他分支代码_【记录】git 拉取远程分支代码,同步到另一个git上...

    最近有需求从某git 上拉取所有分支代码同步到另一git上,现记录操作步骤,以便日后使用: 1:先克隆其中一个分支代码到本地环境 git clone -b test http://账号:密码@XXX. ...

  5. Git:查看所有远程分支以及同步远程代码

    git 查看所有远程分支以及同步 git参考网站:https://www.liaoxuefeng.com/wiki/896043488029600/897271968352576 在多台电脑使用git ...

  6. 小乌龟git如何同步远程分支_git同步远程仓库分支

    git命令 1.何谓同步远程分支?有下面几种情况, 1.本地有新分支,远程仓库没有. 2.远程仓库有新分支,本地没有. 3.本地删除了分支,远程也想删除. 4.远程删除了分支,本地也想删除. 第一种情 ...

  7. git创建远程分支并同步到远程

    创建项目 # 项目初始化 git init 查看分支 # 查看本地分支 git branch # 查看远程远程 git branch -r # 查看本地和远程的所有分支 git branch -a 创 ...

  8. git创建fork仓库和关联fork仓库 git提交新分支之git删除本地分支和git删除远程分支——git remote prune origin同步分支

    git创建fork仓库和关联fork仓库 & git提交新分支之git删除本地分支和git删除远程分支--git remote prune origin同步分支 & 跨分支合并-新建分 ...

  9. Git拉取远程分支到本地,修改并同步

    Git拉取远程分支到本地 本地新建一个空白文件夹folder: 进入folder目录,打开git bash,用命令行初始化git仓库: $ git init 与远程仓库建立连接: // `http:/ ...

最新文章

  1. 3060显卡,送一块!
  2. RDKit:运用RDKit计算USRCAT(形状相似性)
  3. node.js 建立live-server
  4. 一文搞懂ThreadLocal及相关的内存泄露问题
  5. arduinowifi.send怎么获取响应_ChatterBot代码解读-获取对话
  6. dataset的去重计数 g2_向工程渣土运输车辆计数 漏洞损失说“不”
  7. PushMe(交互式)
  8. resultmap的写法_如何向resultMap中的collection中配置的select传递条件
  9. 创建数据库和表的SQL语句
  10. 杨奇龙 mysql 分区_MySQL Group Replication 入坑指北 | By杨奇龙
  11. 八十年代的计算机游戏,儿时小霸王的记忆 八十年代最伟大的二十款游戏
  12. 如何简单的理解TDD与DDT
  13. iconfont阿里矢量图标库使用说明
  14. HTML+CSS登陆界面实例
  15. Mac 系统升级ssh报错
  16. 教你快速使用AD7606的简单驱动方法--并行
  17. 教你用直播大师在局域网内发布组播节目
  18. 企业为何需要在内部推广Devops
  19. Go语言基础之网络编程
  20. 高性能本地缓存Ristretto(二)——过期策略

热门文章

  1. USACO翻译:USACO 2014 FEB SILVER 三题
  2. 剑指offer:合并两个排序的链表
  3. Android中如何使控件保持固定宽高比
  4. 剑指Offer——不用加减乘除做加法
  5. wiki文档书写格式
  6. Django-Json 数据返回
  7. 循序渐进看Java web日志跟踪(2)-Java日志API认识
  8. Java学习计划,给自己一个学习线路
  9. Nuget常用命令(转)
  10. jQuery Todolist