Transferred from: http://zengrong.net/post/1746.htm
- This site is reproduced in addition to the article, are the original site or translation.
- The article welcomes all forms of reprint, but please 18 years of age and above the reprint of the source of the article, respect for my labor, but also respect your IQ;
- This site part of the original and translated articles to provide markdown format source code, welcome to use the source of the article reproduced;
- This blog use wpcmd maintenance;
- This article title: Git view, delete, rename remote branch and tag
- This article link: http://zengrong.net/post/1746.htm
Git view, delete, rename remote branch and tag
- 2015-06-15: Join the sister chapter;
- 2013-11-06: Add the contents of renaming the remote branch;
- 2013-01-09: Added content to delete remote tag.
Sister article: Using Git, git gui, and Tortoisegit
This article records the contents of the remote branch and tag I encountered while using Git, outlining:
- viewing remote branches
- Delete Remote Branch and tag
- Delete local branch that does not exist for the corresponding remote branch
- Renaming a remote branch
- Push local tag to remote
- Get remote Tag
viewing remote branches
With the-a parameter to see the remote branch, the remote branch is shown in red (if you have color support):
$ git branch-a Master remote tungway v1.52* zrong remotes/origin/master remotes/origin/ Tungway remotes/origin/v1.52 Remotes/origin/zrong
Delete Remote Branch and tag
After Git v1.7.0, you can use this syntax to delete a remote branch:
$ GIT push origin--delete <branchName>
Delete tag so used:
Git push origin--delete tag <tagname>
Otherwise, you can use this syntax to push an empty branch to a remote branch, which is actually equivalent to deleting the remote branch:
Git push Origin:<branchname>
This is the way to remove the tag, push an empty tag to the remote tag:
git tag-d <tagname>git push origin:refs/tags/<tagname>
The two grammars work exactly the same way.
Delete local branch that does not exist for the corresponding remote branch
Suppose such a situation:
- I created the local branch B1 and pull to the remote branch
origin/b1
;
- Others use fetch or pull locally to create a local B1 branch;
- I deleted the
origin/b1
remote branch;
- Other people do fetch or pull again does not delete this their local
b1
branch, run git branch -a
also cannot see this branch was deleted, how to deal with?
Use the following code to view the status of B1:
$ git remote show origin* remote origin Fetch URL: [email protected]:xxx/xxx.git Push URL: [Email protected]: Xxx/xxx.git HEAD branch:master remote branches: Master tracked ' git remote prune ' to Remove) (up to date)
At this point you can see that B1 is stale and git remote prune origin
can be removed from the local repository using the.
A simpler approach is to use this command, which deletes the local branch that does not correspond to the remote branch after the fetch:
Git fetch-p
Renaming a remote branch
Renaming a remote branch in git is essentially deleting the remote branch, renaming the local branch, and then resubmitting the remote branch.
For example, in the following example, I need to rename the Devel branch to the develop branch:
$ git branch-av* devel #158 from Gwill/devel master #138 from Tdlrobin/master zrong Export Getfiledata remotes/origin/head- origin/master remotes/origin/add_build_script ' master ' into Add_build_script remotes/origin/devel export getfiledata
To delete a remote branch:
[Deleted] devel
To rename a local branch:
git branch-m devel Develop
To push a local branch:
(48/48 (58/58 (Delta5[New branch] Develop, develop
However, when I was working on GitHub, I encountered this error while deleting the remote branch:
[Remote rejected (deletion of the currentbranch prohibited' [email protected]:zrong/quick-cocos2d-x.git '
This is because in GitHub, Devel is the default branch of the project. To resolve this issue, do this:
- Go to GitHub on the Settings page of the project;
- Set the default Branch to another branch (for example, master);
- Re-executes the Delete remote branch command.
Push local tag to remote
git push--tags
Get remote Tag
Git fetch origin tag <tagname>
Reference articles
- Https://makandracards.com/makandra/621-git-delete-a-branch-local-or-remote
- Http://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-in-github
- Http://www.cnblogs.com/deepnighttwo/archive/2011/06/18/2084438.html
- Http://stackoverflow.com/questions/14040754/deleting-remote-master-branch-refused-due-to-being-current-branch
- http://weli.iteye.com/blog/1441582
Git view, delete, rename remote branch and tag "Go"