Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

git delete all branches except master

git branch | grep -v "master" | xargs git branch -D
Comment

Git delete all branches except master

// -- Clear all branches except Master Branch --
git branch -D $(git branch | grep -v 'master')
// This will clear all your branches you have on local that you have 
// not pushed to your repository. eg: IF, you created a branch that was, 
// not pushed it will remain along with amster. 
// But the others will be cleaned.

// -- Delete a single branch
git branch -D branch-name
Comment

git delete all remote branches except master

git branch -r | grep 'origin' | grep -v 'master$' | grep -v HEAD | cut -d/ -f2- | while read line; do git push origin :heads/$line; done;
Comment

Remove All Local Branches not on Remote

$ git branch -r | egrep -v -f /dev/fd/0  <(git branch -vv | grep origin) | xargs git branch -d
Comment

remove all git branches deleted on remote

# Shorthand for deleting localy all branches already deleted on remote
# set this alias in git.config
git config --global alias.gone "! git fetch -p && git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '$2 == "[gone]" {print $1}' | xargs -r git branch -D"
# then run
git gone
Comment

how to delete all branches in git except master

$ git branch | grep -v '^*' | xargs git branch -D
Comment

git delete all remote branch except master

git branch -r | grep 'origin' | grep -v 'master$' | grep -v 'develop$' | grep -v HEAD | cut -d/ -f2- | while read line; do git push origin :heads/$line; done;
Comment

PREVIOUS NEXT
Code Example
Shell :: push code to github 
Shell :: start fast api server 
Shell :: linux kill a port 
Shell :: remove all files with no extention rm 
Shell :: cannot install ngx-toastr in angular 13 
Shell :: how to run .sh file in background linux 
Shell :: bash random sleep 
Shell :: bash get file full path 
Shell :: install chromedriver linux 
Shell :: requirements.txt conda 
Shell :: Looping over a file lines in bash 
Shell :: error: unknown command "neat" for "kubectl" 
Shell :: Finding Apache http Process 
Shell :: how to deploy on heroku 
Shell :: git view stash 
Shell :: how to download a text file with curl 
Shell :: scheduler ubuntu cmd 
Shell :: how to remove a non empty directory in linux 
Shell :: install native run 
Shell :: installing composer command line 
Shell :: bash array initialization multiple lines 
Shell :: kill tomcat ubuntu 
Shell :: how to open terminal as administrator in ubuntu 
Shell :: how to run spigot server using bat 
Shell :: find string terminal 
Shell :: get data from json array in mysql 
Shell :: delete all files in linux 
Shell :: how to install .sh file in ubuntu 
Shell :: install homebrew git mac 
Shell :: powershell get-childitem 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =