Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»GIT»How to Delete Git Remote and Local Branch

    How to Delete Git Remote and Local Branch

    RahulBy RahulAugust 25, 20152 Mins Read

    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).
        
    branch git
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Create Branch in Git Repository
    Next Article How To Install Ruby on Ubuntu and LinuxMint using RVM

    Related Posts

    How To Add a Git Remote Repository

    3 Mins Read

    How to Git Reset to Head

    Updated:November 3, 20213 Mins Read

    How to Delete a File on Git

    3 Mins Read

    How to Git Stash Changes

    Updated:October 29, 20213 Mins Read

    How to delete Git tags

    Updated:October 25, 20211 Min Read

    How to Create Git tags

    Updated:October 25, 20212 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.