git 跟踪远程分支

本文介绍了如何使用`git branch --set-upstream`命令跟踪远程分支,以及其与`git push -u`和手动配置`remote`和`merge`的等效操作。通过这些方法,可以在本地分支和远程分支之间建立关联。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

命令的最终修改都是针对.git/config文件
1  @  使用--set-upstream去跟踪远程分支        

    git  branch --set-upstream my_branch origin/my_branch

    origin is your remote repo  , you  can add a remote repo : 

    git remote add   [ options]  <name>  <url>

    [ options ]    -f, --fetch           fetch the remote branches

                       -t, --track <branch>  branch(es) to track
                       -m, --master <branch>
                              master branch
                       --mirror[=<push|fetch>]
                               set up remote as a mirror to push to or fetch from
                       

2  @  替代


    该语法等价于第一次提交分支时,使用git push -u origin my_branch
    在第一次提交你的分支的时候使用。它会像git branch --set-upstream一样在本地分支与远程分去建立联系。
    通常我们在新建分支的时候,一定要显式建立这种联系。

3  @  替代

  1. # git remote add  <name>  <url>
  2. # git config branch.master.remote <name>
  3. # git config branch.master.merge  refs/heads/master
4  @  替代
      git  checkout -b my-branch origin/whatever

5  @  原始
      git pull <remote-name> <remote-branch>
   Be careful with this, however: if you are on a different branch and do an explicit pull, the refspec you pull will be merged into the branch you're on!
    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值