2

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant answer. Very simple, but I'm a novice. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.