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:


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


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?

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


  • 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)

  • Thank you for responding, your suggestion is not what I want. What I am looking for is more complicated which takes all user_names and app_names, and compares if any app_name exists twice, thrice and so on. – kenn Dec 11 '16 at 12:41
  • 1
    @kenn ooooh I get it now (I think) - on mobile now but I will figure it out when I get home shortly :) – Zanna Dec 11 '16 at 12:46
  • @kenn managed it I think :) let me know if not! – Zanna Dec 11 '16 at 14:25
  • 1
    @askubuntu.com/users/527764/zanna yep, it works well, thanks! – kenn Dec 11 '16 at 15:20
  • 1
    @kenn awesome :D – Zanna Dec 11 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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