bitbucket

Moved to Git yet?

Hi all friends, this post is describing steps to start using Git if you are an SVN user, a situation that I was in recently myself. I will be copying files over from SVN to Git repository but not migrating the repository history, this could be discussed in another post.

I will be using Bitbucket as my Git repository and SourceTree as my Git client.

Create your first Git repository in Bitbucket

Bitbucket is a Git repository service provided by Atlassian. Bitbucket provides several plans ranging from $10/month to $200/month, but the best thing about it is the free plan. The free plan offers the same features as the paid plans except for limiting the number of users to 5 users, which is 4 more than what is needed for personal projects.

STEP 1 – Sign Up to Bitbucket

bitbucket_logo_landingGo to the URL: https://bitbucket.org/ and follow the process of signing up to the free service.

STEP 2 – Create your first Repository

repos_large

Log in to the new account and in the main dashboard press the ‘Create’ button.

Choose a name for the new repository, the repository URL will be:

https://bitbucket.org/<<username>>/<<repository-name>>

Choose the repository type to be ‘Git’.

Prepare your Work Station

In my case I am using a PC with Microsoft Windows. The process should not be of much difference in case of Linux or Mac OS.

STEP 3 – Install Git

logo@2x

Download Git client at the following URL: http://git-scm.com/downloads

After installing, you can now use Git Bash shell to do pretty much everything you want with your source code repository and working copy. But for this tutorial we are all beginners here and I’d use some GUI to start up with experiencing Git.

STEP 4 – Installing SourceTree

soutcetree_logo_landingSourceTree is a free graphical interface Git client that combines simplicity and power. Download and install Atlassian SourceTree at the following URL: http://sourcetreeapp.com/

Start Using Git

STEP 5 – Checkout Your Project

CloneOpen SourceTree and press the ‘Clone/New’ button at the top left corner. Enter the path for the project repository and where you like your local working folder to be. You will be asked for your BitBucket account credentials.

Clone-Rep

STEP 6 – Add Files to Working Folder

Copy your project files to the working folder you’ve created in the previous step. Ignore the hidden folders called ‘.svn’ if found. For a huge project, you can do that by svn-exporting (and not checking out) the project trunk directly into the Git working folder.

As discussed in the beginning of the post, at the moment we are not concerned with transferring the project history from SVN to the new Git repository. This could be the topic of a following post, or you can refer to these Git tutorials.

STEP 7 – Add Files to Repository

Open SourceTree again and notice that it is now showing all the added files as ‘Untracked’ files which is indicated by the blue question mark icon beside each file.

Untracked

  1. First step in order to add the files to the repository is to stage them. This is done in SourceTree by checking the checkbox beside all the untracked files.
  2. Then comes the commit step, in SVN committing change is copying the modified or added files to the main repository, this is not the case for Git. In Git committing changes is to record the changes to the local repository which is in this case our working folder. More on this in the discussion below. For now let’s commit files waiting in staging. This is done by filling the commit message at the bottom of the screen and pressing the ‘Commit’ button.Commit
  3. PushThe last step is to push changes. This could be done either by pressing the ‘Push’ button at the tool buttons menu. Or you can check the checkbox at (2) to do two steps at one and push right away after committing.

STEP 8 – Modify Files and Commit Changes

Committing changes is very similar to what we discussed in step 7. After modifying a file, open SourceTree. The modified files will appear with a yellow icon beside them in the unstaged area. Check the files you want to commit to move them to the staging area. Next commit changes with an appropriate comment then push them to main repository.

Pulling Files

‘Pull’ is the action similar to the ‘update’ action of SVN. It updates the working folder with changes done by others and pushed earlier to the main repository.

Discussion


How the concept of working directory differs between Git and SVN

One very different approaches using Git is that the concept of working copies is no longer applicable (although I’ve been using the term loosely throughout the post). What is Git is really doing is it considers all copies or the original repository, a repository by itself. This means your working copy is actually your own repository with all set of features by itself.

git-tutorial-basics-clone-repotorepocollaborationHow the concept of commit differs between Git and SVN

Now we know how your local copy is a repository by itself, this describes the reason why a commit doesn’t mean the changes are submitted to the original repository. A commit is actually committing changes to the local repository history. An additional step named ‘push’ is needed to transfer commits from local repository to the original repository. An opposite action called ‘pull’ is when you want to get changes done by other team members from original repository to your local clone.

In addition to the two commit-push steps, Git offers an addition step before you commit which is staging. Think of this as a step to group changes and get them ready for the actual commit. Staging is no altering the history of the repositories in any way. It is just a step for getting things organised before the actual commit.

More information about how to use Git could be found at these Git tutorials. It is using command line not SourceTree though.

Leave a Reply

Your email address will not be published. Required fields are marked *