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.
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.
Just to make sure the terminology is clear…
- Version control system — means of tracking changes to files (usually involving branches, etc.); examples: Git, Mercurial, SVN, TFS
- Repository — collection of files and their changes; this is managed by the version control system
- Host — remote site where repositories are made available to a broader audience; examples: GitHub, Bitbucket
This post will describe how to…
- Install Git on your development machine (assuming you have Windows OS)
- Set up a sandbox repository on Bitbucket (assuming you have a Bitbucket account already)
- Do the three most basic Git workflows — cloning a repo, committing changes, and pushing to a remote host
Caveat emptor: This is not an exhaustive “how to do ___ with Git” post. I want to describe the simplest things to get you started. There will be further posts to explain other workflows.
Note: I chose not to go the GitHub for Windows route because I’m not doing anything with GitHub here; I simply need the Git tools.
- Visit http://www.git-scm.com and download the Git Setup Wizard.
- 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:
git config --global user.name "Your Name" git config --global user.email "email@example.com" git config --global push.default simple
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):
cd /c/dev git clone https://firstname.lastname@example.org/geoffmazeroff/gittestrepo.git cd /c/dev/gittestrepo
Now I’ve got the directory c:\dev\gittestrepo\ on my machine where I can do useful things.
Let’s add a new file called readme.txt. In the console…
…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
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.