git 创建本地分支跟踪远程分支

创建本地分支跟踪远程分支

git branch -r //查看所有远程分支
git checkout -b dev //创建一个本地分支, 并切换到该分支
git checkout --track origin/actualCombat //切换到名字为origin/actualCombat的远程分支
git checkout -b dev --track origin/actualCombat //创建一个名字为dev的本地分支, 并将该本地分支跟踪到名字为origin/actualCombat的远程分支
当git pull不成功时发生以下信息 如图1
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> dev
解决方案:指定当前工作目录工作分支,跟远程的仓库,分支之间的链接关系。
比如我们设置master对应远程仓库的master分支
git branch —set-upstream-to=origin/master master
这样我们每次想push或者pull的时候,只需要输入git push 或者git pull即可。
在此之前,必须要指定想要push或者pull的远程分支

实战:

    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch -a //查看所有分支
    * master
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch -r //查看所有远程分支
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git remote add origin https://github.com/WangXiongShi/vueCli3.git //将当前空的git仓库设置为我的项目
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch -r //查看所有远程分支
      origin/master
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch - a //查看所有分支
    fatal: '-' is not a valid branch name.
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch -a //查看所有分支
    * master
      remotes/origin/master
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch -a //查看所有分支
    * master
      remotes/origin/master
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git checkout -b dev //创建一个名字为dev的本地分支,并切换到该分支
    Switched to a new branch 'dev'
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git push origin dev //将本地分支dev设置成远程分支
    Total 0 (delta 0), reused 0 (delta 0)
    remote: 
    remote: Create a pull request for 'dev' on GitHub by visiting:
    remote:      https://github.com/WangXiongShi/vueCli3/pull/new/dev
    remote: 
    To https://github.com/WangXiongShi/vueCli3.git
     * [new branch]      dev -> dev
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch -r //查看所有远程分支
      origin/dev
      origin/master
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git add . //提交所有工作区的文件到暂存区
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git commit -m '测试将dev设置为远程分支’ //提交所有暂存区的文件到本地版本库
    [dev 4fa2bb7] 测试将dev设置为远程分支
     1 file changed, 32 insertions(+), 58 deletions(-)
     rewrite src/components/HelloWorld.vue (79%)
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git pull //获取本地版本库的最新代码
    There is no tracking information for the current branch.
    Please specify which branch you want to merge with.
    See git-pull(1) for details.
    
        git pull <remote> <branch>
    
    If you wish to set tracking information for this branch you can do so with:
    
        git branch --set-upstream-to=origin/<branch> dev
    
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git branch --set-upstream-to=origin/dev dev //将当前的工作分支dev设置关联远程仓库dev
    Branch 'dev' set up to track remote branch 'dev' from 'origin'.
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git pull //获取本地版本库的最新代码
    Already up to date.
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ git push //将本地版本库推送到远程服务器上对应的分支
    Enumerating objects: 9, done.
    Counting objects: 100% (9/9), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (5/5), 456 bytes | 456.00 KiB/s, done.
    Total 5 (delta 3), reused 0 (delta 0)
    remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
    To https://github.com/WangXiongShi/vueCli3.git
       9f6925a..4fa2bb7  dev -> dev
    wangxiongshideMacBook-Pro:vuecli3 wangxiongshi$ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值