Question

I've just installed git on Ubuntu, now I want to work on my repo in BitBucket. I'm a little confused on how to do so. I can't do the following:

git remote add BitBucketRepo git@bitbucket.org:dir/file.git

As it returns the following error:

fatal: Not a git repository (or any of the parent directories): .git

It clearly is pointing to a git repo, so why is it lying to me?

Also, it is worth noting I am using SSH and I have successfully paired my GitHub account to my computer.

Was it helpful?

Solution

You need to run this command from a local git repository (a directory in which you have run git init or git clone) - otherwise git remote doesn't know which local repo you want to add the remote for.

It should be as simple as cd my-local-dir, where my-local-dir is the directory containing your local (cloned) git repository.

If you don't yet have the repo available locally:

git clone git@github.com:...etc... my-local-dir
cd my-local-dir
git remote add ButbucketRepo git@bitbucket.org...
git push -u ButbucketRepo master

This will clone your code from Github into the my-local-dir directory, add your BitBucket repo as a remote repository, push your code up to Bitbucket and set the local master branch to track the BitBucket remote's master branch.

Tracking means that commands that involve a remote like git push will automatically use the BitBucket remote's master branch. If you don't want that behaviour, skip the -u option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top