git将本地已经存在的分支和一个指定的远端分支建立映射关系
Make an existing Git branch track a remote branch?
Given a branch foo
and a remote upstream
:
As of Git 1.8.0:
git branch -u upstream/foo
Or, if local branch foo
is not the current branch:
git branch -u upstream/foo foo
Or, if you like to type longer commands, these are equivalent to the above two:
git branch --set-upstream-to=upstream/foo
git branch --set-upstream-to=upstream/foo foo
As of Git 1.7.0:
git branch --set-upstream foo upstream/foo
Notes:
All of the above commands will cause local branch foo
to track remote branch foo
from remote upstream
. The old (1.7.x) syntax is deprecated in favor of the new (1.8+) syntax. The new syntax is intended to be more intuitive and easier to remember.
官方文档:git-branch(1) Manual Page
-u <upstream>
--set-upstream-to=<upstream>
Set up <branchname>'s tracking information
so <upstream> is considered <branchname>'s upstream branch.
If no <branchname> is specified, then it defaults to the current branch.
假定,需要把foo分支,和远端的foo分支进行映射,远端名称为upstream
如果当foo分支不是当前分支,使用如下命令
git branch -u upstream/foo foo
如果foo分支是当前分支
git branch -u upstream/foo
==============================================================================
在checkout分支的时候,就进行映射
he ProGit book has a very good explanation:
Tracking Branches
Checking out a local branch from a remote branch automatically creates what is called a tracking branch. Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git push, Git automatically knows which server and branch to push to. Also, running git pull while on one of these branches fetches all the remote references and then automatically merges in the corresponding remote branch.
When you clone a repository, it generally automatically creates a master branch that tracks origin/master. That’s why git push and git pull work out of the box with no other arguments. However, you can set up other tracking branches if you wish — ones that don’t track branches on origin and don’t track the master branch. The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]
. If you have Git version 1.6.2 or later, you can also use the --track
shorthand:
$ git checkout --track origin/serverfix
Branch serverfix set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "serverfix"
To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:
$ git checkout -b sf origin/serverfix
Branch sf set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "sf"
Now, your local branch sf
will automatically push to and pull from origin/serverfix
.
查看本地分支和远端分支的映射情况git branch -vv
查看映射
Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -vv
chucklu_master 8739b35 [chucklu/master] v0.10.16 (mainwindow topmost fix)
* chucklu_zhCN d5dbcc8 1.修改默认语言为中文zhCN
master 8739b35 [epix37/master] v0.10.16 (mainwindow topmost fix)
ui-translation cade481 [epix37/ui-translation] a few more resx entries
发现chucklu_zhCN分支没有和远端建立映射关系
添加映射
Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -u chucklu/chucklu_zhCN
Branch chucklu_zhCN set up to track remote branch chucklu_zhCN from chucklu.
再次查看映射
Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -vv
chucklu_master 8739b35 [chucklu/master] v0.10.16 (mainwindow topmost fix)
* chucklu_zhCN d5dbcc8 [chucklu/chucklu_zhCN: ahead 1] 1.修改默认语言为中文zhCN //可以发现这个已经映射成功了
master 8739b35 [epix37/master] v0.10.16 (mainwindow topmost fix)
ui-translation cade481 [epix37/ui-translation] a few more resx entries
remove the remote tracking branch
https://stackoverflow.com/questions/3046436/how-do-you-stop-tracking-a-remote-branch-in-git
To remove the upstream for the current branch do:
$ git branch --unset-upstream
This is available for Git v.1.8.0 or newer.
git将本地已经存在的分支和一个指定的远端分支建立映射关系的更多相关文章
- git 在本地备份与指定不需要管理文件
git 在本地备份 备份文件夹操作 在本地备份文件夹克隆一个不带工作区的仓库: 哑协议: git clone --bare <workspace>/.git yourwork.git gi ...
- 【git】本地git bash连接远程库github
重要参考: https://www.liaoxuefeng.com/wiki/896043488029600 https://segmentfault.com/a/1190000003728094 正 ...
- git查看本地和创建分支、上传分支、提交代码到分支、删除分支等,git分支、git查看本地和创建分支以及上传分支到服务器
以下是git命令行里边的命令操作 ##进入项目目录下 giscafer@Faronsince2016 /G/002_project $ cd Comments ##查看远程分支有哪些 giscafer ...
- 关于git新建本地分支与远程分支关联问题
背景 新建本地分支并推送到远端后,当前分支没有与远端分支关联,每次推送都需要填写一堆信息. 操作 git branch --set-upstream-to=origin/20160928 切换到本地分 ...
- git推送本地分支到远端 以及删除远端分支的 命令
git推送本地分支到远端 当前处于master分支,尝试用了git push origin warning: push.default is unset; its implicit value is ...
- Git新建本地分支与远程分支关联问题:git branch --set-upstream
Git新建本地分支与远程分支关联问题:git branch --set-upstream git在本地新建分支, push到remote服务器上之后,再次pull下来的时候,如果不做处理会报以下提示: ...
- git 删除本地分支和远程分支、本地代码回滚和远程代码库回滚
[git 删除本地分支] git branch -D br [git 删除远程分支] git push origin :br (origin 后面有空格) git代码库回滚: 指的是将代码库某分支退 ...
- git删除本地分支
远端master分支有更新需要拉取至本地,但是代码有些地方做了修改导致了小冲突,但是这些修改又是无关紧要的,于是就打算直接删除掉本地分支再重新拉取master分支,过程如下: //查看本地分支 git ...
- git在本地向远程仓库创建分支
在本地的仓库种,如果想给upstream创建新分支并关联,需要执行 git push -u/--set-upstream 远程仓库名 远程分支名
随机推荐
- No such file or directory
项目-targets-build phases, 然后从copy bundle resources里面删掉红色的错误资源文件
- 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause
解决方法一: SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); 优点:不用重启mysql 缺点:重启mysql后还会 ...
- 剑指Offer——构建乘积数组
题目描述: 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]. ...
- 如何在 windows 配置 libtorch c++ 前端库?
如何在 windows 配置 libtorch c++ 前端库? 下载 pytorch 已经编译好的库: 此库不带 gpu,主要方便演示.支持 win7 win10 系统. 下载地址:https:// ...
- python 通过文件路径获取文件hash值
import hashlib import os,sys def CalcSha1(filepath): with open(filepath,'rb') as f: sha1obj = hashli ...
- 给Django后台富文本编辑器添加上传文件的功能
使用富文本编辑器上传的文件是要放到服务器上的,所以这是一个request.既然是一个request,就需要urls.py进行转发请求views.py进行处理.views.py处理完了返回一个文件所在的 ...
- Flask蓝图,Session,闪现,中间件等
Session 除请求对象之外,还有一个 session 对象.它允许你在不同请求间存储特定用户的信息.它是在 Cookies 的基础上实现的,并且对 Cookies 进行密钥签名要使用会话,你需要设 ...
- 初识Java集合框架(Iterator、Collection、Map)
1. Java集合框架提供了一套性能优良.使用方便的接口和类,它们位于java.util包中 注意: 既有接口也有类,图中画实线的是类,画虚线的是接口 使用之前须要到导入java.util包 List ...
- 003-shell 传递参数
一.概述 可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 二.实例 以下实例我们向 ...
- RF的优缺点
随机森林有什么优点,如: a. 对于很多数据集表现良好,精确度比较高: b. 不容易过拟合: c. 可以得到变量的重要性排序: d. 既能处理离散型数据,也能处理连续型数据,且不需要进行归一化处理: ...