Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Stackorigin – The Community of Question and Answers

Stackorigin – The Community of Question and Answers Logo Stackorigin – The Community of Question and Answers Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
Home/ Questions/Q 39637
Next
In Process
ashok
  • 0
ashok
Asked: June 13, 20222022-06-13T05:11:02+00:00 2022-06-13T05:11:02+00:00In: Programming

How do I delete a Git branch locally and remotely?

  • 0

How do I delete a Git branch locally and remotely?

localremote
  • 7 7 Answers
  • 51 Views
  • 0 Followers
  • 0
Share
  • Facebook

    Related Questions

    • How do I restart the kernel shortcut Spyder?
    • SQL query to find third highest salary in company
    • difference between AWS sam build and sam deploy
    • Airflow on AWS EC2 instance with Ubuntu
    • python - Delete an element from a dictionary
    • How to check your Ubuntu version
    • How To Find Out My Linux Distribution Name and Version
    • How can i Check Linux distribution name
    • How can i Check Linux distribution name
    • How to Check Python Version on Linux

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    7 Answers

    • Voted
    • Oldest
    • Recent
    1. pratap
      2022-06-13T05:17:13+00:00Added an answer on June 13, 2022 at 5:17 am

      Delete Local Branch

      To delete the local branch use one of the following:

      $ git branch -d <branch_name>
      $ git branch -D <branch_name>
      
      • The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch.
      • The -D option is an alias for --delete --force, which deletes the branch “irrespective of its merged status.” [Source: man git-branch]
      • As of Git v2.3, git branch -d (delete) learned to honor the -f (force) flag.
      • You will receive an error if you try to delete the currently selected branch.

      Delete Remote Branch

      As of Git v1.7.0, you can delete a remote branch using

      $ git push <remote_name> --delete <branch_name>
      

      which might be easier to remember than

      $ git push <remote_name> :<branch_name>
      

      which was added in Git v1.5.0 “to delete a remote branch or a tag.”

      Starting with Git v2.8.0, you can also use git push with the -d option as an alias for --delete. Therefore, the version of Git you have installed will dictate whether you need to use the easier or harder syntax.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. pratap
      2022-06-13T05:17:37+00:00Added an answer on June 13, 2022 at 5:17 am

      To remove a local branch from your machine:

      git branch -d {the_local_branch} (use -D instead to force deleting the branch without checking merged status)

      To remove a remote branch from the server:

      git push origin --delete {the_remote_branch}

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. pratap
      2022-06-13T05:17:55+00:00Added an answer on June 13, 2022 at 5:17 am

      The short answers

      If you want more detailed explanations of the following commands, then see the long answers in the next section.

      Deleting a remote branch

      git push origin --delete <branch>  <span># Git version 1.7.0 or newer</span>
      git push origin -d <branch>        <span># Shorter version (Git 1.7.0 or newer)</span>
      git push origin :<branch>          <span># Git versions older than 1.7.0</span>
      

      Deleting a local branch

      git branch --delete <branch>
      git branch -d <branch> <span># Shorter version</span>
      git branch -D <branch> <span># Force-delete un-merged branches</span>
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    4. pratap
      2022-06-13T05:19:10+00:00Added an answer on June 13, 2022 at 5:19 am

      It’s very simple:

      To delete the remote branch

      git push -d origin <branch-name>
      

      Or

      git push origin :<branch-name>
      

      — You can also delete tags with this syntax

      To forcefully delete local branch

      git branch -D <branch-name>
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    5. pratap
      2022-06-13T05:19:34+00:00Added an answer on June 13, 2022 at 5:19 am

      If you want to delete a branch, first checkout to the branch other than the branch to be deleted.

      git checkout other_than_branch_to_be_deleted
      

      Deleting the local branch:

      git branch -D branch_to_be_deleted
      

      Deleting the remote branch:

      git push origin --delete branch_to_be_deleted
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    6. pratap
      2022-06-13T05:20:10+00:00Added an answer on June 13, 2022 at 5:20 am

      Delete locally:

      To delete a local branch, you can use:

      git branch -d <branch_name>
      

      To delete a branch forcibly, use -D instead of -d.

      git branch -D <branch_name>
      

      Delete remotely:

      There are two options:

      git push origin :branchname
      
      git push origin --delete branchname
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    7. pratap
      2022-06-13T05:20:26+00:00Added an answer on June 13, 2022 at 5:20 am

      To delete your branch locally and remotely

      • Checkout to master branch – git checkout master
      • Delete your remote branch – git push origin --delete <branch-name>
      • Delete your local branch – git branch --delete <branch-name>
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Sidebar

    Ask A Question

    Adv 120x600

    Looking for advertising?

    Consider These Things If You Appreciate What stackorigin Does: Stackorigin is a community where you can ask questions and find answers, for free to everyone. We would appreciate it if you bought us a coffee if you liked what we were doing.

    Buy me a Coffe

    Adv 120x600

    • Random
    • Answers
      • On: April 29, 2023
      • Answers: 0

      What is DOCTYPE?

      • On: August 4, 2022
      • Answers: 0

      How purchase Asacol United States, How asacol hd works

      • On: August 9, 2022
      • Answers: 0

      Zovirax compre online, Can zovirax inside mouth

      • On: July 4, 2022
      • Answer: 1

      Where can I buy slim fit men's trousers?

      • On: August 2, 2022
      • Answers: 0

      Where can I find information about Cefuroxime in the Netherlands?, ...

    • strapcart_online
      strapcart_online added an answer The problem of impotence is seen in men over 65… May 30, 2023 at 6:32 am
    • strapcart_online
      strapcart_online added an answer Aurogra 100 Tablet is used to permanently remove the problem… May 25, 2023 at 9:03 am
    • strapcart_online
      strapcart_online added an answer There are many ED pills on the market to overcome… May 12, 2023 at 7:19 am
    • strapcart_online
      strapcart_online added an answer It can become serious if the problem of ED is… May 2, 2023 at 9:39 am
    • hari
      hari added an answer sudo apt updatesudo apt install python3-pipsudo apt install sqlite3sudo apt… May 2, 2023 at 7:08 am

    Adv 120x600

    Trending Categories

    Health
    2049Questions
    , 4Followers
    Programming
    1271Questions
    , 0Followers
    Technology
    216Questions
    , 3Followers
    General Knowledge
    131Questions
    , 0Followers
    Business & Finance
    84Questions
    , 4Followers

    Adv 120×600

    Stats

    • Questions 4k
    • Answers 1k
    • Best Answers 105
    • Users 129

    Users

    alexande005

    alexande005

    • 1 Question
    • 0 Answers
    michaelstraker

    michaelstraker

    • 1 Question
    • 0 Answers
    Bulgaria

    Bulgaria

    • 0 Questions
    • 0 Answers
    armandobreeze

    armandobreeze

    • 0 Questions
    • 0 Answers
    annasent

    annasent

    • 0 Questions
    • 0 Answers

    Adv 120×600

    Explore

    • Recent Questions
    • Most Answered
    • Answers
    • No Answers
    • Most Visited
    • Most Voted
    • Random
    • Polls

    Footer

    Stackorigin - The Community of Question and Answers

    Stackorigin

    Stackorigin is the world’s largest Q&A networking site, Stackorigin community brings you the collaboration of all the various Questions and the related Answers given by the community.

    About

    • About Us
    • Contact Us
    • FAQ
    • Submit Guest Post Article on Technology, Education, Health, Apps, Gadgets, IoT, AI, Business, Digital Marketing and More

    Info

    • Privacy Policy
    • Terms and Conditions
    • Community Guidelines
    • Tags

    Products

    • Tutorials
    • Advertising
    • Categories
    • Corona
    • StackHow

    Follow

    © 2022 Stackorigin. All Rights Reserved.

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.