14

I work with a team on a very large project and we use git and bitbucket for our version control.

Because there are a lot of old branches in our git repository our project leader asked us to delete all our old branches that we don't use anymore.

How do I only see the branches that I created in the web UI? So I can delete them easily.

4
  • 3
    You can't, really (git doesn't know anything about "who created a branch")...and this is why using a shared repository is generally a bad idea. Use your own repository, and submit changes as pull requests, and you avoid this problem.
    – larsks
    Jan 5, 2018 at 15:30
  • It is probably possible to see branches that you made commits to, on the command line. Some combination of scripts to run git branch and then for every branch run git log and filter or grep on your username , maybe also limiting to a given date back in time.
    – user985366
    Jun 26, 2018 at 11:15
  • 1
    What do you mean by "your branches"? What makes a branch yours? Dec 17, 2020 at 21:23
  • @TomerShetah the branches I created
    – J_rite
    Feb 17, 2021 at 10:34

4 Answers 4

1

I feel to suggest you some steps from command line.

I think that you can start listing all of the branch created by you:

git for-each-ref --format=' %(authorname) %09 %(refname)' --sort=authorname | grep 'youauthorname'

After that you can easily delete those branches with:

git push -u --delete branch1 branch2 ...

Let me know.

1
  • This isn't a direct answer, but it's useful!
    – Andrew
    Jul 7 at 14:47
0

Yes it is possible to know who created or deleted a branch in Bitbucket server but you need access to Database. Whenever a branch is deleted the hash moves from a revision number to series of 000000000 and vice-versa in case of branch creation. You can check the same using following commands after connecting to DB:

A) select * from sta_repo_push_ref | grep <branch_name>;

and look for something like below where first column is activity id and third column value is '1' which means branch creation:

20034 | refs/heads/feature_<branch_name> | 1 | 0000000000000000000000000000000000000000 | 1e624235uhjdhhghlb6200cdbc86a4458fc1dfbf5 

B) select * from sta_activity where id = 20034; which will give you user_id in last column:

20034| 6 | 2019-09-09 18:24:24.864 | 34

C) Finally select * from sta_normal_user where user_id = 34; and here is name who created the branch.

user_id | name | slug | locale | deleted_timestamp | time_zone
---------+----------------+----------------+--------+-------------------+-----------
34| <Culprit_Name> | <Culprit_Name>| | |
1
  • This is only a viable approach for Bitbucket Server. You will not get this sort of access to the Bitbucket Cloud database. Sep 24, 2019 at 21:23
0

It may be easier to do this on the client side.

From the terminal you should be able to use: git log --author=<your email> --format=%H %D

This will list the short hash for all commits created by you followed by any branches pointing to those commits. Unless someone else committed to your branch, this should include all of your branches.

Keep in mind, this will include local branches as well of those on the server. Branches on the Bitbucket server will begin with <remote name>/. Unless you have designated another name for your remote, then this will typically be origin.

Be sure to git fetch, before you get started.

As a side note, if you want to avoid this in the future, I would suggest putting your name or initials in the branch name. For example, xyz/myBranch. This will make it easier to locate branches created by you in the future.

0

in my ~/.gitconfig I have this

[alias]

# branch owners(last commit) on remote 
        bown = for-each-ref --sort=committerdate refs/remotes/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(authorname) (%(color:green)%(committerdate:short)%

then I just go like this git bown | grep my-name

Note: this only relies on last commit owner

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.