Difference between revisions of "Git How-To"

From RoboJackets Wiki
Jump to navigation Jump to search
(SSH Accounts)
Line 1: Line 1:
==SSH Accounts==
+
==Public Key==
Before using Git, you will need to have an ssh account on our server to get access.  Contact the robojackets network manager to create an account. The username is the one used for the robojackets account, and should be typed '''without''' brackets. Verify this account as follows in a terminal:
+
Before using Git, you have to get access to our repos. The software we use to manage Git access requires your "public key."
<pre>
+
 
ssh [username]@robojackets.org
+
To get access, follow the instructions in this link to generate the public key for your computer.
</pre>
+
[https://help.ubuntu.com/community/SSH/OpenSSH/Keys#Generating_RSA_Keys]
You should be asked for a password, and then will have logged in.  Because git uses ssh as its primary means of communication, and you'll need to log in a lot, you'll want to set up passwordless login from your own system.  You'll do this by creating an RSA public key with the steps as follows in a terminal on your machine.  
+
 
<pre>
+
This process will produce a public key file (~/.ssh/id_rsa.pub)
ssh-keygen
+
You should send or copy this email to the IGVC project manager, who will add it to the Git system and grant you appropriate permissions.
[press enter at each prompt for defaults]
 
ssh-copy-id -i ~/.ssh/id_rsa.pub [username]@robojackets.org
 
ssh [username]@robojackets.org
 
</pre>
 
At the last step, you should have been able to log into the server without a password.
 
  
 
==Getting Code from the Server==
 
==Getting Code from the Server==

Revision as of 12:33, 13 September 2013

Public Key

Before using Git, you have to get access to our repos. The software we use to manage Git access requires your "public key."

To get access, follow the instructions in this link to generate the public key for your computer. [1]

This process will produce a public key file (~/.ssh/id_rsa.pub) You should send or copy this email to the IGVC project manager, who will add it to the Git system and grant you appropriate permissions.

Getting Code from the Server

Currently, the software team uses Git, so you will need to clone your team's repository to your machine as follows in the folder of your choice:

Robocup
git clone ssh://[username]@robojackets.org/git/robocup/software software
IGVC
git clone ssh://[username]@robojackets.org/git/igvc igvc

This will check out a copy of the repository. For those of you that have used SVN before, remember that committing only commits to the local (on your machine) repository, and you need to "push" to put something on a different machine.

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 ssh://[username]@robojackets.org/git/robocup/software

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:

git 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.

git pull

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:

git push