Git is a source code management tool which means it allows users to maintain a repository of "current" code, and whereby any changes to that code are documented. The Murdoch Atmospheric Science group uses BitBucket as a central, online home to all the current versions of code used by the group.

Note: with a BitBucket account you can also store code in private repositories, so a great way to learn how to use git and BitBucket is simply by pushing, pulling, editing and committing some code from your PC.

Before getting started:

  1. Register with BitBucket.
  2. Download git: If you're using Windows, download Git for Windows which includes Git GUI (i.e. point-and-click graphical interface) or Git Bash (Unix/Linux-style command line interface).
  3. Configure git for use: Using git (or Git Bash), enter the following commands to set-up git for future use:
$ git config —global "Your Name Goes Here"
$ git config —global ua.ude.hcodrum|sserdda.liame#ua.ude.hcodrum|sserdda.liame

Setting up repositories:
BitBucket has a fairly self-explanatory step-by-step guide to creating new repositories which appears if you click on 'Create', so this wiki will only cover those bits that are a bit ambiguous.
A folder where you keep your code is, in git-speak, a project. In order to make this project 'speak' to BitBucket, from inside this folder, type:

$ git init
$ git remote add origin

The folder on your computer is now referred to as the master, while the repository on BitBucket is the origin.

Git Basics:
Most actions can be done using only a few simple commands. Possibly the most important of these, though, is the commit command, which documents what code you've added or edited.

Cloning an existing repository:
$ git clone
$ git clone origin

This will replicate everything in an already existing repository (such as one of the shared repositories on BitBucket) and copy it into the current project directory. Then you're free to edit this code as you wish.

Adding new code to a repository:
$ git add filename.m

Sends a new file to the staging area ready to be committed.

Committing code:
$ git commit
$ git commit -m "your message"

This commits all the actions you've done up to this point. Up to this point, any code you've added has been sat in a staging area waiting to be committed. At this point you'll be asked to enter a message which will be saved to document your changes. You can also do this directly using the -m option.

Pushing to BitBucket:
$ git push -u origin master

This pushes the committed changes in the master (i.e. your current project) to the origin (i.e. your repository on BitBucket).

Pulling from BitBucket:
$ git pull
$ git pull
$ git pull origin

This will pull down any new files that are present in the origin repository

Finding Out More:
The Git Basics chapter of Pro Git is probably the best place to go to learn more.

Note: I (fiona) don't think git is installed on Epic - if someone knows this to be wrong, let me know!

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License