美文网首页
Git分支操作

Git分支操作

作者: Dsiner | 来源:发表于2021-08-04 12:37 被阅读0次

    用户配置

    1、设置提交代码时的用户信息:

    git config --global user.name "name"
    git config --global user.email "name@email.com"
    

    如果去掉 --global 参数只对当前仓库有效。

    2、使用以下命令生成 SSH Key:

    ssh-keygen -t rsa -C "name@email.com"
    

    之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。

    分支操作

    创建分支(基于当前分支):

    git branch branchname
    

    切换分支:

    git checkout branchname
    

    上传本地分支branchname到远程服务器,如果当前分支与多个主机存在追踪关系,则可以使用-u选项指定一个默认主机,这样后面就可以不加任何参数使用git push:

    git push -u origin branchname
    

    合并分支rebase:

    git rebase branchname
    git rebase --continue // 出现冲突,解决冲突后继续
    git rebase --abort // 或中断操作
    

    合并分支merge:

    git merge branchname
    git commit // 出现冲突,解决冲突后提交
    git merge --abort // 或中断操作
    

    删除分支:

    git branch -d branchname // 普通删除
    git branch -D branchname // 强制删除
    

    删除本地的远程分支:

    git branch -r -D origin/branchname
    

    删除远程git服务器上的分支:

    git push origin -d branchname
    

    强制推送:

    git push -f origin branchname
    

    切换远程仓库地址:

    git remote set-url origin URL
    

    相关文章

      网友评论

          本文标题:Git分支操作

          本文链接:https://www.haomeiwen.com/subject/mjkuvltx.html