Cloning clones the wrong repo

Advait October 12, 2023

I have several repositories on BitBucket. I want to clone one of them to a server. The steps I follow are as per the following:

1. Go to the repository's page on BitBucket and click on the clone button (HTTPS)

2. Go the terminal and paste the command.


After doing this, it seems to clone the wrong repository, another one in my account. Inside the newly created directory are completely unrelated files.

After asking someone else for help, when they entered their link from their page, git still asked for my account's app password. I have removed my stored credentials.

I removed and re-added the remote, deleted all the stored credentials. But each time, it's always the wrong repository.

`.git/logs/HEAD` shows that it was cloned from the right repository, it's just all the data is wrong.

2 answers

1 accepted

0 votes
Answer accepted
Advait October 17, 2023

I finally figured out why it was behaving the way it did! I was placing cloning the files in a privileged directory,, so while all other commands were run as a normal user, I had to clone using `sudo`, and then mark it safe or change ownership. So all other preferences, stored credentials and settings were the user's stored settings, the cloning command was run as the root.

To fix the program, I essentially cleared `/root/.gitconfig`, as opposed to `/home/$USER/.gitconfig` and then it worked!

Keeping this here in case someone else is as clueless as me.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 18, 2023

Hi @Advait,

Thank you for the update, it's good to hear that the issue is resolved!

Please keep in mind that it is not recommended to delete the .gitconfig if you plan to make commits on this server. Git will complain that the author identity is unknown if you try to make a commit in that clone. In case this happens, you can recreate the file and set author email and name with the commands

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Kind regards,
Theodora

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 13, 2023

Hi @Advait and welcome to the community!

  • Is this a Bitbucket Cloud repository? Does its URL start with https://bitbucket.org/ ?

  • What is the format of the clone URL? Does it look like the following or is it different?
    https://username@bitbucket.org/workspace/repo.git
  • When you clone a repo, you should see in the working directory the source code of the repo's main branch. If the repo has multiple branches and you want to see the code of another branch, you will need to checkout and pull this other branch.

    Can you double-check the branch that is cloned with the command git branch, afterwards run ls -lah, and then compare that with the source code of the same branch on Bitbucket website?

  • You mentioned that this issue occurs when you try to clone a repo on a server. Do you see the same issue if you clone the repo using the same URL on your own computer?

Kind regards,
Theodora

Advait October 13, 2023

Hi @Theodora Boudale Thanks for responding

1. Yes, it is a BitBucket cloud repository with the same URL

2. Yes, the same format

3. Both are master.

4. Good question. When I tried it, it did clone the correct repository. So it seems to be an issue with Git? I did specifically remove all settings and saved credentials, so what else can I do to remove the memory it seemingly has?

Thanks

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 13, 2023

Hi @Advait,

Can you please check the ~/.gitconfig file on this server and see if there is an entry like the following?

[remote "origin"]
      url = https://username@bitbucket.org/workspace/repo.git

Please note that this file is located at the home directory of the server's user you are logging in, it is not the .git/config file that is located inside a clone.

I can reproduce this issue if such an entry exists in the ~/.gitconfig file. If this is the case, you will need to remove this part from the file, save it, and then do another clone.

Please feel free to let me know how it goes.

Kind regards,
Theodora

Advait October 13, 2023

@Theodora Boudale I can confirm that line isn't present. Moreover, I also tried removing that file altogether but that didn't change anything

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 16, 2023

Hi @Advait,

Can you also please check the following files?

  • /etc/gitconfig

  • ~/.config/git/config

  • In case this server is running Windows (I am quoting from the Git book):
    On Windows systems, Git looks for the .gitconfig file in the $HOME directory (C:\Users\$USER for most people). It also still looks for [path]/etc/gitconfig, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer. If you are using version 2.x or later of Git for Windows, there is also a system-level config file at C:\Documents and Settings\All Users\Application Data\Git\config on Windows XP, and in C:\ProgramData\Git\config on Windows Vista and newer.

Check these files for the line

[remote "origin"]
url = https://username@bitbucket.org/workspace/repo.git

where workspace/repo is the repo that is wrongly cloned.

If you still cannot find them, you can do a search for the text workspace/repo in all of the server's files to figure out any config file with this remote definition.

It is expected to find this remote definition in the .git/config file of a clone of this repo, but it shouldn't be in any user- or system-wide config.

Kind regards,
Theodora

Advait October 16, 2023

Hi @Theodora Boudale ,

I am using Linux, and neither of the 2 files you specified exist. I did grep for the string but it did not return any results.

I also restarted the system just to be safe. But it still cloned the wrong repo :(

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 17, 2023

Hi @Advait,

Can you please execute the following command on the terminal you use to clone, and then post the full output here so I can take a look? This will show all Git-related configurations and the file where each config setting is stored.

git config --list --show-origin

Please make sure to sanitize (replace with dummy values) sensitive/private data in the output (if any) prior to sharing.

Kind regards,
Theodora

Advait October 17, 2023

Hi @Theodora Boudale ,

Great news! I was able to fix the issue! I've added it as another answer so I can pin it for others.

Thanks for all your help!!

 

 

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events