You'll need to download and install git from git.com. Use all of the default choices in the installer. Once you've done this, you can run all of the commands below in Git Bash. Access Git Bash by right-clicking on your desktop and selecting "Git Bash".
Before using Git, you have to get access to our repos. The software we use to manage Git access requires your "public key."
To generate your public key:
- Create the .ssh directory
- Linux users:
mkdir ~/.ssh<br/>chmod 700 ~/.ssh
- Windows users:
- The directory already exists at C:/Users/[username]/.ssh/
- Linux users:
- Generate your ssh key
ssh-keygen -t rsa
This process will produce a public key file (id_rsa.pub) in the directory you created. You should send or copy this file to your project manager, who will add it to the Git system and grant you appropriate permissions.
Getting Code from the Server
Our code, electronics designs, design report, and data sheets are stored in Git repositories. To get access to these, you need to "clone" the correct repository to your machine.
git clone firstname.lastname@example.org:igvc/software.git igvc/software
git clone email@example.com:igvc/electrical.git igvc/electrical
git clone firstname.lastname@example.org:igvc/docs.git igvc/docs
Changing Remote to the Server
If you got the code off of a flash drive, you will need to reset your local copy of the git repository to use the server instead. Go into your software folder and execute:
git remote rm origin git remote add -t master -m master origin email@example.com:igvc/software.git
Committing Local Changes
As you add changes and make something work, you should commit your changes to your local repository. This will allow you to manage changes by making use of git, if you want to go back. Once you have something working, execute the following command:
git commit -a
You will add a meaningful commit message to say what you did. This is important so that other people can understand what you are doing. After committing, you can check that you have committed things by running status:
Updating Your Local Repository
Because other people are making changes to the repository on the server, you will need to update your local repository from time to time to get these new changes. You should do this just before any commits to a server so that you don't break the build on the server.
You may need to jump through some hoops to merge things properly if there are conflicts.
You can set up an alias to automatically update multiple repositories. For example, if you have the software, electronics, documentation, and mechanical repositories inside a folder called robocup, you can add the following line to your .bashrc file located in your home folder.
alias update_robocup='echo "Checking..."; cd /home/UserName/robocup/electrical; echo "Electrical: "; git pull; cd ../mechanical; echo "Mechanical: "; git pull; cd ../robocup_docs; echo "Documentation: "; git pull; cd ../software; echo "Software: "; git pull; cd ../; echo "Done!";'
You'll probably have to edit that to work with the exact file structure you are using.
Committing Changes to the Server
Once you think you have something that should go on the server, you should first check to make sure it works, because if your code breaks the build no one will like you any more and all of the cool kids won't invite you to cool things and everyone will point fingers at you when you walk around campus. Commit all of the changes to your local repository and then push:
Branches allow us to keep separate instances of the code base for work on individual features. You will often create a branch of the code while you work on fixing a bug or adding a feature, then merge the changes from your branch to the "master" branch when you are done. Here is a summary of the branching workflow:
- Create a new branch with this command. Our branch names follow the convention "usrname-taskname". This naming scheme allows us to quickly see who's working on what.
git branch branchname
- Write your code, and commit your changes.
- Use PULL to update and merge in changes from the master branch. You need to do this to make sure your changes still work with any new changes on the master branch.
- If you want to save yourself some trouble, commit and pull often.
- This command needs to be run while you are on your feature branch for the changes to be merged into your feature branch.
git pull origin master
- Once you've fixed any merge conflicts and tested that the code works with all of the combined changes, checkout the master branch to merge the changes from your branch.
git checkout master git merge branchname
- Finally, push your merge to the remote server
If you ever want to see all of the branches in the system, use the following command.
git branch -a
The branch you are currently on will be marked with an asterisk(*).