2

I have a local directory and a remote git repository. Both contain the same files. However, the local directory is not yet connected to the remote repo. How can I connect them? The commands I have tried so far did not work because the local directory is not empty.

Not sure if this makes a difference but the local folder and the remote repo do not have the same names.

1
  • What commands did you try? Please put them to your question.
    – abto
    Commented Aug 22, 2015 at 5:50

2 Answers 2

4

git remote set-url origin //path/to/repo.git

and either

git pull origin [your branch] or git push origin [your branch]

10
  • I'm getting error "fatal: Not a git repository (or any of the parent directories): .git" Is that because my local directory is not yet a git branch? If so, how do i make it one? Commented Aug 21, 2015 at 18:42
  • that error sounds like the path you entered wasn't a valid git repo. double-check that path. you can check if you are in a branch by typing git status.
    – Leroy
    Commented Aug 21, 2015 at 18:44
  • Hm, I checked it by entering "git remote -v" and I used the output of that. So like this: git remote set-url origin https://github.com/myOrganization/myRepo.git Commented Aug 21, 2015 at 18:50
  • make sure you include https:// in the path. so https://github.com/myOrganization/myRepo.git
    – Leroy
    Commented Aug 21, 2015 at 18:51
  • I did. It wasn't visible in my comment above at first because I forgot the quotes to display it as code but I fixed it. I entered it with the https://. Just to be clear, because I'm dense, on the command line I am inside the local directory that I want to link up to the existing git repo. However, the local directory is not yet a repo itself. It contains no .git folder. Do I have to initialize it first for git remote set-url origin https://github.com/myOrganization/myRepo.git to be successful? Commented Aug 21, 2015 at 18:56
1

If I understand you well, you want to link two local directories, of which one is already a git clone:

cd your/NOT/git/clone/dir
git init .
git remote add origin http...
git fetch -p --all

And to really "link" you two directories, you could even add a local remote:

git remote add file:///path/to/original/local/clone

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