giftbling.blogg.se

Git delete branch after merge
Git delete branch after merge









git delete branch after merge

Then I do some double job unfortunately and ask git for log again for each branch but now it's formatted. Here I compare our first query with git branch -r -merged to get common lines that would match the both queries. First I want to get a list of them with the commit date and the commiter:Ĭomm -12 <(git log -remotes -decorate-refs-exclude=tags/* -decorate-refs-exclude=heads/* -no-walk -no-merges -before=3month -pretty=%D | tr, '\n' | xargs -n1 | sort) <(git branch -r -merged | xargs -n1 | sort) | xargs -I " | sort -k2 -r -t "|" | column -t -s "|" Ok, the job is done but I've decided to delete MERGED branches older than 3 months. Now just finish the job with deleting merged remotes: git branch -r -merged | xargs -n1 git branch -r -D So you deleted all remote branches (both merged and non-merged) with the last commit older than 3 weeks. Then we just use xargs to tell git to delete each branch (we don't care about space padding here, xargs trims them: xargs -n1 git branch -r -D So we get our list of remote branches to delete: origin/MH-7788 Then we split several refs in a line: tr, '\n' Origin/mh-7854-manchkin-edit, origin/manchkin-edit

git delete branch after merge

So we get something like that: origin/MH-7788 Also we could probably want to skip merges ( -no-merges) since they probably don't reflect actual work on branches.

git delete branch after merge

We filter out tags and local branches from the decorated refs with -decorate-refs-exclude=tags/* -decorate-refs-exclude=heads/*. So here first we obtain last commits ( -no-walk) older than 3 weeks ( -before=3week) in remote branches ( -remotes) and print decorated ref names ( -pretty=%D). We could filter only non-merged branches here through git branch -r -no-merged but it doesn't make much sense for your particular task you want to achieve. Why we begin with it? Because it includes both merged and non-merged branches with commits older than 3 weeks which you both want to delete. Git log -remotes -decorate-refs-exclude=tags/* -decorate-refs-exclude=heads/* -no-walk -before=3week -no-merges -pretty=%D | tr, '\n' | xargs -n1 git branch -r -D Let's begin with the second complex query:











Git delete branch after merge