Git手册 - 分支远程同步
2017-06-15 10:30
267 查看
一)将本地分支连接到远程分支,这里以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
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
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
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
相关文章推荐
- git fork别人的项目之后 同步远程分支的方法
- git对submodule多模块的tag操作(并同步到远程分支)
- git fork别人的项目之后 同步远程分支的方法
- git gui & git bash 的简单操作手册 - 从远程同步数据到本地
- git设置远程同步分支
- git从远程到本地,拉取分支,拉取项目,从其它分支拉取,推送,同步的操作
- Git使用手册/Git教程:git branch 分支操作、创建分支、查看分支、删除分支、删除本地分支、删除远程分支
- git删除远程分支后,本地同步问题
- git 远程分支同步
- Git 远程分支的删除与同步
- git同步远程分支
- Git使用手册/Git教程:git fetch 将远程仓库的分支及分支最新版本代码拉取到本地
- 同步本地远程分支 git remote prune origin
- git命令行删除远程分支和同步
- git 同步脚本&& git clone 远程分支
- git 更新本地分支与远程同步
- git 同步远程已删除的分支和删除本地多余的分支
- git远程、本地分支的同步
- Git 远程分支的删除与同步
- 本地仓库 同步到 bitbucket 远程git库