My e-Notes about Cloud, K8s, OpenShift, DataScience, Machine Learning, Python, Data Analytics, DataStage, DWH and ETL Concepts

Breaking

Wednesday, 2 December 2020

GIT - How to delete Local & Remote Branch

Github is an wowsome tool for code versioning and its comes with lot of functionality. But today we will look into Branch deletion process. 

Deleting a Local Branch:  
             You can not delete a branch if you are already inside it, so if you want to delete a branch named - "test_branch" you have to switch to some other branch first. 

$ git checkout master        # switch to any other branch
$ git branch -d test_branch  # delete the local branch 


Sometime, if branch have some uncommitted changes then it will throw error. You can use below command to force the deletion. 

$ git branch -D test_branch  # delete the local branch forcefully 


Deleting a Remote Branch:  
    It is a good practice to sync the remote branch details into local repo first, before deleting any remote branch, which we can do by running below command - 

$ git fetch -p

Now, we can delete the remote branch by following below command template - 

$ git push remote_name -d branch_name  # delete the remote branch 

i.e. - Usually, remote_name is 'origin' so the command will be - 

git push origin -d test_branch



Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed     Telegram Group

No comments:

Post a Comment

Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.