Sunday, December 25, 2011

How to use Bitbucket to remotely control your git projects

Bitbucket is an interesting service that allows to remotely store git and mercurial projects. It is reliable, easy to configure and free. Most important, you can have as many private repositories as you want.

In this post I'll explain how to commit and init a remote git repository on bitbucket starting from a local git repository. This is what I usually do in my projects: I start them locally, then commit locally via git and finally backup a remote copy via bitbucket.

These are the steps necessary to do that:
  • create a remote empty git repository on your account at
  • if you haven't already a local git repo, initialize your project locally by typing git init 
  • copy your standard .gitignore file in the project root directory
  • commit locally (using the commit command or with a GUI tool like gitx, gitc, or gitk)
At this point you're ready to commit remotely. First of all your local git environment must be setup to point to the remote repository:

git remote add origin https://<username><username>/sampleproject.git

Here I assume that your project is named sampleproject; you must substitute the <username> key with your bitbucket account name.

If everything goes fine, you're ready to do your first push on your bitbucket repo:

git push -u origin master

To fetch the remote project from another machine just type:

git clone https://<username><username>/sampleproject.git

No comments:

Post a Comment