• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Delete Git Remote and Local Branch

Written by Rahul, Updated on August 25, 2015

Generally we don’t recommend to remove any branch from git repository for production sites. But sometimes you may need to delete any existing git branch from your repository. For example git repository has corrupted files or usefulness files which is no more required in future.

This article will help you to delete git remote and local branch in repositories.

  • Delete Remote Git Branch:

    – Use the following command to remove any branch from remote server. Following example will remote branch named “stage1” from remote git repository.

    $ git push origin --delete stage1
    
    Username for 'https://github.com': rahul
    Password for 'https://[email protected]':
    To https://github.com/tecadmin/firstrepo.git
     - [deleted]         stage1
    
  • Delete Local Git Branch:

    If you also want to remove git local branch. Use the following command to remove it.

    • List all local branch names using following command.
      $ git branch
      
        master
      * stage1
      
    • As per last command output, you can see that your are currently using “stage1“. So If you try to remove this branch, you will face following error.
      $ git branch -d stage1
      
      error: Cannot delete the branch 'stage1' which you are currently on.
      
    • Change to different branch to remove ‘stage1‘.
      $ git checkout master
      
      Switched to branch 'master'
      Your branch is up-to-date with 'origin/master'.
      
    • Now delete the stage1 branch using following command. This time it will delete branch successfully.
      $ git branch -d stage1
      
      Deleted branch stage1 (was cc8ebe7).
      

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy