代码管理Git-建立 Remote Branch 的相關指令操作

转自:http://blog.longwin.com.tw/2013/11/git-create-remote-branch-2013/ 


Git 建立 遠端 Branch

  1. git clone git@github.com:user/project.git
  2. cd project
  3. git checkout -b new_branch # 建立 local branch
  4. git push -u origin new_branch # 建立遠端 branch (將 new_branch 建立到遠端)
  5. git fetch
  6. vim index.html # 修改
  7. git commit -m 'test' -a # commit
  8. git push
  9. 註: new_branch 要換成你要的 branch name, 以上所有 new_branch 都要對應著修改成同樣名稱.

Git 使用 遠端 Branch

  1. git clone git@github.com:user/project.git
  2. cd project
  3. git branch -r # 看遠端有什麼 branch
  4. git checkout origin/new_branch -b new_branch # 建立 local new_branch 並與遠端連接
  5. vim index.html # 修改
  6. git commit -m 'test' -a # commit
  7. git push
  8. 註: new_branch 要換成你要的 branch name, 以上所有 new_branch 都要對應著修改成同樣名稱.

Git 刪除 遠端 Branch

  • git push origin :new_branch # 刪除遠端的 branch

Git Branch 的 Merge

  1. git branch new_branch # 建立 branch
  2. git checkout new_branch # 切到 new_branch, git checkout -b new_branch 可以同時建立 + 切換
  3. vim index.html # 修改
  4. git commit -m 'test' -a # commit
  5. git checkout master # 切回 master
  6. git merge new_branch # 將 new_branch merge 到 master
  7. git branch -d new_branch # 若砍不掉就用 -D

更新所有 Repository branch

  • git remote update

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在 git 中,你可以使用 `git branch` 命令来查看当前的分支,例如: ``` $ git branch * master develop ``` 其中 `*` 号表示当前正在使用的分支。你还可以使用 `git branch -a` 命令来查看所有的分支(包括远程分支): ``` $ git branch -a * master develop remotes/origin/master remotes/origin/develop ``` 如果要切换到其他分支,你可以使用 `git checkout` 命令,例如: ``` $ git checkout develop ``` 这样就可以切换到名为 `develop` 的分支。 如果你想追踪远程分支,你可以使用 `git branch --track` 命令,例如: ``` $ git branch --track my-feature origin/my-feature ``` 这样就会在本地创建一个名为 `my-feature` 的分支,它会被设置为追踪 `origin/my-feature` 远程分支。这样,你就可以在本地对远程分支进行操作,例如提交代码或者合并分支。 如果你想停止追踪某个分支,你可以使用 `git branch --unset-upstream` 命令,例如: ``` $ git branch --unset-upstream my-feature ``` 这样,`my-feature` 就不再是追踪分支,它就成了一个普通的本地分支。 ### 回答2: 在Git中,追踪分支是指将本地分支与远程分支建立关联,使得本地分支能够跟踪远程分支的变化。以下是几个常用的Git追踪分支的相关指令: 1. 克隆一个远程仓库: ``` git clone <远程仓库地址> ``` 2. 查看本地分支和远程分支的关联: ``` git branch -vv ``` 3. 创建一个新的本地分支并与远程分支关联: ``` git checkout -b <新分支名> <远程分支名> ``` 4. 修改当前分支与远程分支的关联: ``` git branch -u <远程分支名> ``` 5. 拉取远程分支的最新代码到本地分支: ``` git pull origin <远程分支名> ``` 6. 推送本地分支到远程分支: ``` git push origin <本地分支名>:<远程分支名> ``` 7. 删除本地分支和远程分支的关联: ``` git branch --unset-upstream ``` 以上是一些常用的Git追踪分支的指令,可以帮助我们在本地与远程分支之间保持同步,并方便地进行代码的合并和推送。 ### 回答3: Git 追踪分支是指在Git版本控制系统中,我们可以创建一个与远程仓库分支相关联的本地分支,从而能够追踪远程分支的更新并进行同步。 以下是一些常用的Git追踪分支相关的指令: 1. 创建一个本地分支并与远程分支进行关联: ``` git checkout -b <branch_name> origin/<remote_branch_name> ``` 这将创建一个本地分支,并将其与指定的远程分支进行关联。 2. 检出一个已经存在的远程分支到本地: ``` git checkout -b <branch_name> origin/<remote_branch_name> ``` 这将检出并创建一个与指定的远程分支同名的本地分支。 3. 拉取并合并远程分支的更新: ``` git pull origin <branch_name> ``` 这将拉取并合并指定的远程分支的最新更新到当前的本地分支。 4. 推送本地分支的更新到远程分支: ``` git push origin <branch_name> ``` 这将将当前的本地分支的更新推送到指定的远程分支。 5. 查看所有的远程分支: ``` git branch -r ``` 这将显示所有的远程分支。 6. 查看已跟踪的远程分支: ``` git branch -vv ``` 这将显示所有已跟踪的远程分支。 通过使用以上这些指令,我们能够在Git中轻松地追踪和同步远程仓库的分支。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值