git 分支批量操作命令
作者:互联网
来源: https://digitaldrummerj.me/git-remove-local-merged-branches/
After a while your list of local git branches can get a bit out of control especially if you doing all of your development on a branch, creating a pull request, merging it to main and then deleting the remote git branch when it is merged into main. Once the branch is deleted on the remote repository there is no need to keep it locally anymore.
Below is the command to delete all local branches that have been merged into the main branch. If you git trunk branch is not main or you want to remove all branches that have been merged into a different branch than main, just change the 2 places in the command that say main to what your branch name is.
Deleting Branches Merged into Main
-
Open git bash and navigate to your git repository that you want to clean up
-
Fetch the latest from the git
git fetch
-
See the list of local git branches
git branch
-
Delete all local branches that have been merged to main branch
git branch --merged main | grep -v "^\* main" | xargs -n 1 -r git branch -d
-
See the list of local git branches that remain
git branch
Deleting Local Branches That No Longer Exist on the Remote
-
Open git bash and navigate to your git repository that you want to clean up
-
Fetch the latest from the git
git fetch
-
See the list of local git branches
git branch
-
Delete all local branches that have been merged to main branch
git branch -vv | grep ': gone]' | grep -v '\*' | awk '{ print $1; }' | xargs -r git branch -d
-
See the list of local git branches that remain
git branch
标签:git,branches,批量,branch,操作命令,main,local,Copy 来源: https://www.cnblogs.com/whm-blog/p/16369758.html