git deletes remote branch and tag related commands _git operations

Source: Internet
Author: User
Tags tagname using git
This article records the contents of the remote branch and tag that I encountered while using Git.
View Remote Branch Delete remote branch and tag Delete no local branch for remote branch rename remote Branch push local tag to remote FETCH remote TAG View Remote branch Plus-a parameter to view remote branches, remote branches are represented 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 remove a remote branch:


$ GIT push origin--delete <branchName>
Delete tag for this:
$ Git push origin--delete tag <tagname>


Otherwise, you can use this syntax to push an empty branch to a remote branch, which in fact is equivalent to deleting a 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 kinds of grammar function are exactly the same.


Delete a local branch that does not have a corresponding remote branch


Suppose such a situation:


I created the local branch B1 and pull to the remote branch origin/b1;
Others create local B1 branches locally using fetch or pull;
I removed the ORIGIN/B1 remote branch;
Another person performing the fetch or pull does not delete the local B1 branch, and running Git branch-a does not see how the branch is removed and how it is handled.
Use the following code to view the status of the B1:


$ git Remote show origin
* Remote origin
Fetch Url:git@github.com:xxx/xxx.git
Push Url:git@github.com:xxx/xxx.git
Head Branch:master
Remote branches:
Master tracked
REFS/REMOTES/ORIGIN/B1 stale (use ' git remote prune ' to remove)
Local branch configured for ' Git pull ':
Master merges with remote master
Local ref configured for ' Git push ':
Master pushes to-master (up to date)
At this point you can see that B1 is stale, and using git remote prune origin can be removed from the local version library.


The 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 remote Branches


Renaming a remote branch in git means deleting the remote branch first, renaming the local branch, and then submitting a remote branch again.


For example, in the following example, I need to rename the Devel branch to the develop branch:


$ git Branch-av
* Devel 752bb84 Merge pull request #158 from Gwill/devel
Master 53b27b8 Merge Pull request #138 from Tdlrobin/master
Zrong 2ae98d8 Modify Ccfileutils, export Getfiledata
Remotes/origin/head-> Origin/master
Remotes/origin/add_build_script d4a8c4f Merge branch ' master ' into Add_build_script
Remotes/origin/devel 752bb84 Merge Pull request #158 from Gwill/devel
Remotes/origin/devel_qt51 62208f1 update. Gitignore
Remotes/origin/master 53b27b8 Merge Pull request #138 from Tdlrobin/master
Remotes/origin/zrong 2ae98d8 Modify Ccfileutils, export Getfiledata
To delete a remote branch:


$ git push--delete origin devel
To Git@github.com:zrong/quick-cocos2d-x.git
-[deleted] Devel
To rename a local branch:


git branch-m devel Develop
Push local Branch:


$ GIT push origin develop
Counting objects:92, done.
Delta compression using up to 4 threads.
Compressing objects:100% (48/48), done.
Writing objects:100% (58/58), 1.38 MiB, done.
Total (delta), reused (Delta 5)
To Git@github.com:zrong/quick-cocos2d-x.git
* [New Branch] Develop-> develop
However, when I was working on the GitHub, I encountered this error while removing the remote branch:


$ git push--delete origin devel
Remote:error:refusing to deletes the current Branch:refs/heads/devel
To Git@github.com:zrong/quick-cocos2d-x.git
! [Remote rejected] devel (deletion of the current branch prohibited)
Error:failed to push some refs to ' git@github.com:zrong/quick-cocos2d-x.git '
This is because in GitHub, Devel is the default branch of the project. To resolve this issue, do the following:


Enter the Settings page for the project in GitHub;
Set the default Branch to another branch (for example, master);
Re-execute the Delete remote branch command.
Push local tag to remote


git push--tags
Get remote Tag


Git fetch origin tag <tagname>

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.