本地分支和远程分支的创建与合并

创建本地分支、提交到远程分支

  1. 常用指令

    $ git remote -v //可以查看你当前项目的远程git地址 
    $ git status //查看当前代码状态,改动,所在分支,当前状态有没有代码冲突等
    $ git branch -a //就是查看远程的所有分支列表了,
    $ git branch //是查看本地的git分支。绿色代表当前项目所在的分支,红色就是远程分支列表。
    $ git branch -d test     //删除分支
    $ git checkout test//切换分支
    $ git pull origin //更新当前指向的分支,当前分支与远程分支已经存在追踪关系
    $ git diff test//查看分支代码改动
    $ git merge test  //合并test到master上
  2. 查看本地分支

    $ git branch \* master  
  3. 查看远程分支(remotes开头的代表是远程分支)

    $ git branch -a * master  
    remotes/origin/master 
  4. 创建本地分支,并切换到分支

    $ git branch test
    $ git checkout test
    Switched to branch 'test'
    $ git branch  
    master \* test 
  5. 本地提交到远程

    $  git gui //此时会出现一个窗口根据提示操作就好了
  6. push到远程(第一次无法pull,只能push)

    $ git push origin test:test
  7. 从远程pull

    $ git pull origin test:test  
    Already up-to-date.

合并分支到master上

  1. 假如我们现在在dev分支上,刚开发完项目,执行了命令下列命令

    $ git add 
    $ git commit -m ‘test' 
    $ git push -u origin test
  2. 然后我们要把dev分支的代码合并到master分支上 该如何? 
    首先切换到master分支上

    $ git checkout master
  3. 如果是多人开发的话 需要把远程master上的代码pull下来

    $ git pull origin master
  4. 如果是自己一个开发就没有必要了,为了保险期间还是pull然后我们把dev分支的代码合并到master上

    $ git merge test
  5. 然后查看状态

    $ git status
    接着会提示你有n个commit,需要push到远程master上 
  6. 执行下面命令即可

    $ git push origin master

猜你喜欢

转载自www.cnblogs.com/nolaaaaa/p/9131499.html
今日推荐