git分支的创建,切换,删除

注:变量参数都会被“( )”所标注

1.远程仓库连接    git remote add  (remotename )(resporistyURL)

remotename:自定义一个本地的分支名,任何不存在的分支名都可以

 repositoryURL:远程仓库链接


2.分支操作

    创建分支 git  branch  [分支名]    (是 `git checkout -b [分支名]`的缩写)

    新建分支并切换到那个分支上去 git checkout  -b (new branchname)

    分支切换    git checkout  [分支名] 

    合并分支    git merge [分支名]     (注:将分支名合并到本分支上)

    删除分支(删除分支之前必须先切换到别的分支) git branch -d (branchname)


3.Git与远程仓库的相应操作 

    git add .

    git commit -m “(注释)”

    git fetch (remotename) (branchname)

    git push (remotename)  (branchname)      (branch大多是branchname)

4.Git撤销  git add 操作   git rm --cached -r .(“.”点不要落了)

--cached指不要删除本地文件

5.所遇到的特殊报错

            fatal: refusing to merge unrelated histories

解决办法:$ git pull 后面加--allow-unrelated-histories完事

6.替换分支

```

git checkout oldMaster // 切换到要被替换的分支

git reset --hard newMaster // 将oldMaster 替换成 newMaster

git push origin oldMaster --force // 再推送到远程仓库

```

如果仅仅替换远程

```git push origin develop:master -f```

即可


图1.报错截图

7.删除分支

删除本地分支  git branch -d branchName  //这种删除需要branchName先合并到主分支上再进行删除

                        git branch -D master  = git brach --delete --force master
删除远程分支  git push --delete   origin/brach

仅删除追踪分支 git push --remotes --delete origin/master

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。