Reputation: 696
I have the below scenario in which I need to migrate the changes from Gerrit to GitLab. We have maintained many branches in the Gerrit which has so many files.
Now I would like to migrate only the latest branches that created on the remote branches.
git fetch
gets the remote branch names in local.git branch -r
lists all the branches from the remote.Is there any Git command we have which lists only the latest 30 remote branches based on created date or last commit also would do fine.
I would like to combine the command with git branch -r | grep origin/*
.
Upvotes: 0
Views: 875
Reputation: 30868
Git does not trace when and by whom a branch is created. The branch creation events may be traced in Gerrit logs and it would also help if your Gerrit is using audit-sl4j. If you don't track the dates in any other methods either, it's almost impossible to retrieve the precise creation dates of branches.
The remote branches are pointing at certain commits. If it's acceptable to sort the remote branches with the committer dates of these commits as primary keys, you could try:
git branch -r --sort=committerdate | tail -30
# or, if for scripted use
git for-each-ref refs/remotes --format="%(refname)" --sort=committerdate | tail -30
The result is just approximate because a newer branch may have been created from an older commit.
Upvotes: 1