Git view, delete, rename remote branch and tag "Go"

Source: Internet
Author: User
Tags using git

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:

    1. viewing remote branches
    2. Delete Remote Branch and tag
    3. Delete local branch that does not exist for the corresponding remote branch
    4. Renaming a remote branch
    5. Push local tag to remote
    6. 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:

    1. I created the local branch B1 and pull to the remote branch origin/b1 ;
    2. Others use fetch or pull locally to create a local B1 branch;
    3. I deleted the origin/b1 remote branch;
    4. 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:

    1. Go to GitHub on the Settings page of the project;
    2. Set the default Branch to another branch (for example, master);
    3. 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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.