Software builder, group fitness instructor

Getting Started with Git and Bitbucket – Part 1

This post is mainly for developers that have heard of Git and would like to take it for a test drive on a repository (repo) that isn’t public. My use case is that I don’t want to embarrass myself by having future employers/colleagues seeing me flail around in some do-nothing repo that I use just for testing purposes. There’s also an assumption that you have a basic working knowledge of source control, preferably distributed version control.

Upfront clarification

For the software development community, GitHub is apparently where all the cool kids hang out. GitHub is a service/website that hosts your Git repos; it also provides some other features (e.g., issue tracking, wikis). In the spirit of open-source, as long as your repos are public, you can have them hosted for free on GitHub. What if you want a private sandbox for experimentation but are low on spare cash?

Bitbucket allows you to have as many private repos as you like for free. (You can make them public later on if you desire.) When you create a repo, you’ll be prompted to select a source control system — Mercurial or Git.

Installing Git

Stick with the default options; however when given the option to adjust your PATH environment, you’ll have to choose which makes sense for you. (I chose “Use Git and optional Unix tools from the Windows Command Prompt” so that I can have only one command shell to contend with. Plus, I already have a console which is way cooler than the stock Windows version.)

Another side note: In ComEmu, you can easily get access to Git Bash if you prefer that shell and want to get the UI niceties of ComEmu as well.

Establishing initial settings

Here are some commands to run in the console to set things up for your system:

Setting up a Bitbucket repo

Log in to Bitbucket.

Click Create near the top of the page.

Set up your repo basically like the view below, then click Create repository.

Establishing your local repo

Now that you have an existing (albeit empty) repo in Bitbucket, we’ll need to have something locally to commit against. Let’s say you’ve got a directory named c:\dev\ where all your coding projects live, and that’s where this sandbox project should live as well.

On Bitbucket, go to the page for your project and find the Clone link.

You’ll be shown a command string that you can copy and paste into your console to clone/download your new repo.

Here’s what I typed into my console (I was prompted for a password during the clone portion):

Now I’ve got the directory c:\dev\gittestrepo\ on my machine where I can do useful things.

Making changes

Let’s add a new file called readme.txt. In the console…

git status

…we get a message about an untracked file, so let’s add it:

git add .

You can also do git add readme.txt for just the single file. (The above command adds all untracked files.) Now we’re ready to commit our changes:

git commit -m "Added a readme file for the project"

Pushing to a remote repository

At this point let’s assume we’ve added, removed, and modified whatever files are involved and have committed those changes locally. Now we need to push our local copy of the repo up to Bitbucket:

git push origin

What’s Next

Following the 80-20 rule, this post should have armed you with enough knowledge to do basic work in Git and have your work hosted on Bitbucket. For the next post, I’ll cover the basics of keeping work separated with branches.