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 [email protected]: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.
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 [email protected]:...etc... my-local-dir
cd my-local-dir
git remote add ButbucketRepo [email protected]...
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.