Git手册 - 分支远程同步

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

1)进入本地项目主分支

2)运行以下命令:

#git remote add origin [email protected]:path/repoName.git        //将远程仓库命名为origin

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

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

注:

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

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

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

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

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

#git push

二)克隆远程仓库

1)通过SSH

git clone  [email protected]: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

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

时间: 2024-08-15 10:10:12

Git手册 - 分支远程同步的相关文章

使用git和github远程同步个人项目

有时, 需要在家里和公司远程同步个人探索性项目. 比如,我现在在学习 python , 在家里构建了一个目录结构, 不愿意在公司重新做相同的事情: 同样,在公司可能会编写新的代码,直接同步给家里. 显然, 通过邮箱拷贝来拷贝去的方式已经过时了. 既然 github 可以进行代码托管, 为什么不使用它呢? 主要步骤如下: 1.  安装 cygwin 和 cygwin 下的 git , 测试 git 命令可用;   参考: https://cygwin.com/install.html 2.  注册

Git使用手册/Git教程:git fetch 将远程仓库的分支及分支最新版本代码拉取到本地

相关文章: 关于验证是否存在ssh配置以及生成SSH Key的方法可以参照文章:Git使用手册:生成SSH Key 关于SSH Key的使用和公钥在gitHub.gitLab的配置等,请参考文章:Git使用手册:使用SSH Key及配置SSH key公钥 关于GIT 工作区.暂存区.本地仓库.远程仓库的概念及关系,请参考文章:Git使用手册:工作区.暂存区.本地仓库.远程仓库 关于GIT 从远程仓库下载项目到本地工作区的操作,请参考文章:Git使用手册:git clone 克隆下载远程仓库项目工

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

最近有需求从某git 上拉取所有分支代码同步到另一git上,现记录操作步骤,以便日后使用: 1:先克隆其中一个分支代码到本地环境 git clone -b test http://账号:密码@XXX.git 2:查看本地分支 git brach 3:查看远程分支 git branch -r 4:查看远程所有分支  远程分支会用红色表示出来(如果你开了颜色支持的话 git branch -a 5:-a命令并没有每一次都从远程更新仓库信息,我们可以手动更新一下 git fetch origin gi

[git] git拉取远程仓库,同步远程分支,解决冲突

[git] git拉取远程仓库,同步远程分支,解决冲突 1.本地仓库存在 本地仓库与远程master已绑定 1.拉取远程分支到本地 git fetch origin dev(远程分支名) 2.在本地创建该分支并切换 git checkout -b dev(本地分支名) origin/dev(远程分支名) 3.把分支代码拉取到本地 git pull origin origin dev(远程分支名) 2.本地仓库不存在 1.克隆远程仓库 git clone 远程库地址 2.拉取远程分支到本地 git

工作中常见的Git本地分支与远程分支同步场景

Git 是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理. ??一直以来本人使用 Git 处理分支都是现用现查,一是因为怕出错,二还是因为懒,作为一名四年开发经验的前端来说,可以说是一件比较尴尬的事情,为避免某天在众人面前出糗,现默默总结记忆下,告别懒惰.(:面子也是进步的动力呢! ??多分支开发便于版本管理,便于协同开发,这需要本地分支与远程分支分别建立 track 关系,如果未 track , push 和 pull 等命令将无法正常实现.本文针对常见的三种场

git使用小结二: git的分支和远程仓库

上一篇文章介绍了git的本地基本操作,如果你不需要和他人协作,比如说你自己写一本书,自己写一个小程序,自己写个网站等等,那么已经差不多够用了.但是分享和协作才是自由世界的主题,git也正是为此而生,所以努力成为一个热爱分享和协作的同学吧!^_^ git的仓库的概念可以理解为git管理的那个文件夹,而git远程仓库可以理解为存放在服务器上的大家都可以用git访问的一个git管理的文件夹.(原谅我的大白话,虽然事实必定比这种解释高大上,不过我个人感觉这么理解也无伤大雅-)而要理解远程仓库,就需要理解

git和github -3 同步到远程仓库

Git命令 git remote — 查看远程仓库的名字 -v — 查看远程仓库对应的地址 -origin — 远程仓库的名字 git push 仓库名(默认是origin) 分支(master) — 同步到远程仓库 默认:git push origin master 添加新的协作人员 1. 点+New collaborator,然后Add collaborator 同步更新代码 && 多人协作解决冲突 git fetch — 从远程拉取数据进行对比,需要手动合并(建议) git diff

git本地与远程分支

已经有远程分支,在本地检出,并且关联到远程分支 git checkout --trach origin/远程分支名 git checkout -b 本地分支名  origin/远程分支名 $ git checkout --track origin/dev $ git checkout -b dev origin/dev 没有远程分支,本地有一个分支,要推送到远程 git push --set-upstream origin 分支名 git push -u origin 分支名 git push

git拉取远程分支并切换到该分支

整理了五种方法,我常用最后一种,这五种方法(除了第4中已经写了fetch的步骤)执行前都需要执行git fetch来同步远程仓库 (1)git checkout -b 本地分支名 origin/远程分支名 (2)git checkout --track origin/远程分支名 (这种写法是上面的简化版,效果完全一样) (3)git checkout -t origin/远程分支名(这种写法是2的简化版) (4)fetch指定的一个分支:git fetch [repo] [remote_bran