How to see only my branches in BitBucket?
Asked Answered
I

4

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.

Interesting answered 5/1, 2018 at 15:26 Comment(4)
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.Lytta
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.Lactary
What do you mean by "your branches"? What makes a branch yours?Frisket
@TomerShetah the branches I createdInteresting
H
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.

Haff answered 17/2, 2022 at 10:32 Comment(1)
This isn't a direct answer, but it's useful!Therapeutics
O
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>| | |
Overawe answered 24/9, 2019 at 5:20 Comment(1)
This is only a viable approach for Bitbucket Server. You will not get this sort of access to the Bitbucket Cloud database.Orianna
N
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.

Nephro answered 18/7, 2022 at 13:7 Comment(0)
C
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

Cooperate answered 11/4, 2023 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.