This is a hands-on guide to learning git. It assumes you have access to the engineering login servers, and (for part 3) that you are working together with a small group.
Part 1: Create a local git repository, do some work
cd mkdir git-test cd git-test git init .
Now add a file, and make a series of commits
nano README <write some stuff, save it> git add README git commit -m "Readme"
Repeat this a few times
Finally, you can see your commit history here:
git log --patch
Part 2: Create a remote git repository, upload your changes
cd mkdir helloworld cd helloworld git init . nano HelloWorld.java
Fill out hello world.
git add HelloWorld.java git commit -m "Added hello world"
compile it, and run it.
Now make a remote repository
ssh <uniquename>@login.engin.umich.edu cd ~/Public mkdir helloworld.git git init --bare helloworld.git exit
Now, back in your development directory:
cd ~/hellworld/ git remote add origin <uniquename>@login.engin.umich.edu:Public/helloworld.git git push origin master
Part 3: Collaborate with a small group (2-3 students)
Start with everyone grabbing the same copy of an existing template:
git clone git://umbrella.eecs.umich.edu/home/jhstrom/animals.git cd animals javac *java java Main
Decide with your group which person will fix the implementation for "Dog", "Pig" and "Cow" (only one per person)
After fixing your code file, make sure the output is correct by recompiling and rerunning. Then make a commit out of this
git add <filename> git commit -m "<your-message>"
Now, setup a remote repository:
ssh <uniquename>@login.engin.umich.edu cd Public mkdir animals.git git init --bare animals.git exit
Locally, setup a new remote to point to that repository
git remote add <uniquename> <uniquename>@login.engin.umich.edu:Public/animals.git git push <uniquename> master
Your changes have now been uploaded.
Now, try to get the code from your groupmates. You will need to add a remote for each person:
git remote add <their-uniquename> <my-uniquename>@login.engin.umich.edu:~<their-uniquename>/Public/animals.git git fetch <their-uniquename>
Check that the right commit was uploaded for each person by typing
git log -p <uniquename>/master
for each groupmate.
Now, on one persons computer, try to merge all the changes together;
For each of the other people in your group,
git merge <uniquename>/master
Then recompile and run the program again.
At the end, check that all the commits have been integrated. A good way to do this is with gitk, a full-featured git GUI. It allows you to see all the commits that have been made, and check which commits are available from which remotes.
You should see something like: