git - Git: completely delete unrelated branch both locally and on remote
问题描述
I accidentally manage to create a completely detached branch in the beginning of the project, and I would like to completely remove it, both from the local and the server repositories.
I am not sure how this happens, but I think the process went something like this:
- I created an empty repository on our git-server (via the web interface). I think it is running gitlab, but it may be some other open source server.
- One of my collaborators made commits to his own branch and pushed them.
- I then made commits to master and pushed them.
Probably I did something stupid when pushing without first pulling or something. Most likely I forced something as well, but it was quite a long time ago so I cannot remember exactly.
I have attached a screenshot from Sourcetree where the first commits in each branch is seen. The blue branch (named something else) is the main branch we have been working on. The red one (called master) is completely useless.
My question is, how can I completely remove the master branch? Preferably I would like to actually delete the commit (it is just nonsense). Also, I would like to be able to rename our current branch to "master".
Is there a way to do this?
解决方案
Delete the branch locally:
git branch -D master
Delete the remote branch:
git push --delete <remote> master
Rename the current branch to "master":
git branch -m <branch named something else> master
Push the "new master" branch to the remote repo:
git push -u <remote> master
推荐阅读
- ansible - 将 local_tmp 设置为 ansible 变量
- python - 使用给定函数获得输入数字的最少重复次数
- vue.js - async vuex fetch action state filled if using variable in template getting error undefined
- python - 从循环中更改多个屏幕的 kivy 小部件属性
- django - django - 将多个实例传递给表单并将其保存在数据库中
- java - 如何在persistence.xml 中设置默认的Eclipselink CacheCoordinateType?
- ios - TableViewCell 仅返回 Nil
- c - C - 什么 *(long *)(host->h_addr); 做?
- android - Android Studio:未编译的 XML 文件作为参数传递?
- unity3d - 将对象旋转到鼠标方向