1

I frequently clone github repos and try them in my computer. Unfortunately github repos can have the same name as another user's repo name.

For example:

https://github.com/user1/app_name.git
https://github.com/user2/app_name.git

When I clone a repo in terminal like

git clone https://github.com/user1/app_name.git

it saves the repo under name after the slash like

app_name

If I clone the second repo, I get the repo exists message and cloning repo aborts.

I just noticed that, and I want to know which repos aborted in that way.

To find them I did something like

history |  grep github.com

but this lists hundreds of lines and it's difficult to pick up the repos with the same app_name and different user_name.

It must be a very easy task for a regex query, but how?

1 Answer 1

1
history | grep -o 'github\.com.*' | tr '/' ' ' | sort -k3 | uniq | uniq -D -f2

Explanation

  • grep -o 'github\.com.*' get the lines that include github.com and trim off the start of the line (like the number of the item in the history etc) to make it easier to deal with the fields
  • tr '/' ' ' change / into spaces because uniq doesn't have an option to set a non-whitespace delimiter...
  • sort -k3 sort the lines using the third (last) field, putting the lines with the same app_name.git together
  • uniq remove duplicate lines
  • uniq -D -f2 ignoring the first two fields, print only the duplicate lines, (so only print the line if there is more than one instance of app_name after removing completely identical lines, indicating that there are multiple users for the same app_name)

If you want to avoid the command itself appearing in the output, you can pipe from grep -o 'github\.com.*' ~/.bash_history instead of history | grep -o 'github\.com.*' (although this won't include commands from the current session)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .