Git Walkthrough - TomHulme/306-Swarm-Robotics-Project GitHub Wiki

1. Install Git:

Assuming you are using Ubuntu, open terminal.

$ apt-get install git

Follow the prompts. Simple

2. Set configs:

Git needs to know who you are to keep track of your commits. So, in Terminal, type

$ git config --global user.name "[your github username]"

$ git config --global user.email "[the email you used for github]"

$ git config --global credential.helper 'cache --timeout=3600'

3. Initialise local repository:

First off, in the file explorer (or terminal, if you want), create a folder that will hold the repository. Then in Terminal, navigate to the folder and type:

$ git init 

This will create all the git related files

4. Pull the project from github

Now you need to pull the project from the github repository. First, you need to tell your local git where it is pulling from (you may be asked to provide your password at some point here. If you have set the timeout to 3600, you won't be asked again for an hour):

$ git remote add github https://github.com/TomHulme/306-Swarm-Robotics-Project.git

Next, we pull the project:

$ git pull github master

And you are done. You now have a copy of the project on your local drive.

5. Making a commit

When you have finished working on the ticket or task you were doing [NB. Make sure your code works before commit!], these steps are the workflow we should follow to safely push your changes to the repository:

$ git add -A

This command adds all the new files to the currently tracked file list, as when you add a file it isn't automatically picked up by git. [Actually it is more complicated than that, but you can look it up if you're interested]

$ git commit -a -m "[some commit message here]"

This will commit the changes to your local repository, with some message associated with it. Your message should be a short one line message, with a small description of the changes you've made, and with the keyword 'fixed' followed by the issue number. eg: "Altered a.cpp, added b.cpp. Fixed #42" Next, you need to pull down the branch you are working on [for these examples, we're working on the master branch], so as to avoid messy merge problems later:

$ git pull github master

This will pull down the latest changes, and attempt to merge them into your local repository. Ideally this will have no problems, but occasionally there will be merge issues which will have to be dealt with. However for now, lets imagine everything is working perfectly. You next need to push to github:

$ git push github master

And the change had been committed.

6. Dealing with merge issues

//TODO

7. Working on Branches

//TODO

8. Useful Commands

To delete local files and fetch the current remote, use these 2 commands:

$ git fetch --all
$ git reset --hard github/<insert branch name here>