4

I'm having problems adding a remote repository to my local one. I first tried using Tower where I manged to add my local repo, but when it came to adding a remote repo it just said add the URL. It doesn't say anything about this URL. Should it include ssh:// my username etc. etc.

So I found this article and followed it precisly, until it came to adding a remote repository. It failed. Can anyone help?

Kasper-Srensens-MacBook-Pro:~ Kasper$ git remote add origin ssh://kasperso@kaspersorensen.com:2227/www/mechatronicscluster/wp-content.git fatal: Not a git repository (or any of the parent directories): .git Kasper-Srensens-MacBook-Pro:~ Kasper$

caneclap
  • 95
  • 3
  • 4
  • 10

3 Answers3

8

You have to be in a git repository to add a remote for this specific repository. Use cd to change the current directory.

Simon
  • 31,675
  • 9
  • 80
  • 92
  • Thanks for your replies. I tried to cd into the lcoal git, ran the same command still getting an error. `Kasper-Srensens-MacBook-Pro:wp-content Kasper$ git status # On branch master nothing to commit (working directory clean) Kasper-Srensens-MacBook-Pro:wp-content Kasper$ git remote add origin ssh://kasperso@kaspersorensen.com:2227/www/mechatronicscluster/wp-content.git fatal: remote origin already exists. Kasper-Srensens-MacBook-Pro:wp-content Kasper$` – caneclap Feb 18 '11 at 11:46
  • Then the remote is already added I guess. Type `cat .git/config` to see the config file for your repo and check if the remote is there. – Simon Feb 18 '11 at 14:00
  • Yeah it seems like it. but now I just have another problem, I can't push my local repository to remote. See my terminal output in my comment below. – caneclap Feb 18 '11 at 20:50
3

Note: if you had to execute that command outside of that exact git repository, you can set the GIT_DIR environment variable:

(
    GIT_DIR=/somewhere/else/.git; export GIT_DIR
    git <command>...
)

or simply using the --git-dir option to your command

    git --git-dir=/somewhere/else/.git <command>...

That would be for commands which don't need to be in a working tree (a checked out Git repository). git remote add fits this criteria.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. useful info, as you can see from my comment above, i didn't have luck even if I was in the local git repo. – caneclap Feb 18 '11 at 11:47
  • @Kasper: what does '`git remote -v`' shows? It is very possible that the remote 'origin' has already been defined, but not for the address you want. You can add your address as a remote named "something else" than 'origin', and goes from there. – VonC Feb 18 '11 at 12:30
  • Thanks, i tried everything over again, but it seems like I always run into a wall `Kasper-Srensens-MacBook-Pro:wp-content Kasper$ git remote -vorigin ssh://kasperso@kaspersorensen.com:2227/www/mechatronicscluster/wp-content.git (fetch) origin ssh://kasperso@kaspersorensen.com:2227/www/mechatronicscluster/wp-content.git (push) Kasper-Srensens-MacBook-Pro:wp-content Kasper$ git push origin master ssh: connect to host kaspersorensen.com port 2227: Operation timed out fatal: The remote end hung up unexpectedly Kasper-Srensens-MacBook-Pro:wp-content Kasper$` – caneclap Feb 18 '11 at 20:47
  • @Kasper: check your ssh config with http://stackoverflow.com/questions/922210/unable-to-git-push-master-to-github/922461#922461 – VonC Feb 18 '11 at 21:03
0

Using for example bitbucket you can easily create remote branch through their web service and then fetch remote repository in Tower (it will add new branch icon)

Michal Gumny
  • 1,770
  • 1
  • 16
  • 24