Question

I have an existing project that I want to share and push to a remote BitBucket git repository. I created a repository on BitBucket and have to clone it :

git clone https://myusername@bitbucket.org/myusername/myproject.git

However I get the following error message:

fatal: destination directory '/path/to/myproject' already exists.

So I would have to remove the files and the directory of the project, clone the repository, and paste the files into the project again... or am I doing something wrong? Why can't I simply clone into a non-empty directory and add/commit the existing files? What is the reason?

PS: I'm on Windows.

Was it helpful?

Solution

If you have an existing project you can synchronize it with your repository by setting the remote location and pushing it up.

If you don't have an existing project you can create one easily using the commands:

$ cd /path/to/my/local/project
$ git init
$ git add *
$ git commit -m "My initial commit message"

From the BitBucket page entitled "Push up an existing repository" that's shown when creating a new repo:

$ cd /path/to/my/local/repo
$ git remote add origin git@bitbucket.org:mike/myrepo.git
$ git push -u origin --all # pushes up the repo and its refs for the first time
$ git push -u origin --tags # pushes up any tags

After this point you can push and pull just as you would normally do.

OTHER TIPS

git clone is for downloading a copy of your repo.

See the documentation.

Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the cloned repository's currently active branch.

If you do not wish to pull the latest active branch, as indicated by the fact that you are simply going to paste files back into the project, use git init. Documentation.

git-init - Create an empty Git repository or reinitialize an existing one

You will then need to add the endpoint for your BitBucket repo to your local repo. BitBucket explains this process here.

I think you're getting something wrong. To 'clone' a repository would mean to copy all of its contents to an empty folder of your choice, so you can later push, pull, etc from there. It's usually the first step you do when you begin working on a new repository.

Now if you made some changes to the files in the repo on your computer and you want them to apply to the online repo too you need to 'add' those changes, then to 'commit' them and finally to 'push' them (through the Git Shell/Bash that is)

So what I usually do is: Go to my repository directory (through the shell) and type:

git add *
git commit -a -m "MyCommitMessage"
git push

Then it will ask for your username and pass and you're done.

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