Introduction To Version Control With Git: Originally by Andreas Skielboe
Introduction To Version Control With Git: Originally by Andreas Skielboe
Most images adapted from Pro Git by Scott Chacon and released under
license Creative Commons BY-NC-SA 3.0.
See http://progit.org/
Any file can be recreated by getting changes from the database and
patch them up.
Git Basics
Each commit in the git directory holds a snapshot of the files that were
staged and thus went into that commit, along with author information.
Note that Git will only let you push to bare repositories.
Fear not! We are starting to get into more advanced topics. So lets look
at some examples.
Get help
$ git help <verb>
With your local working copy you can make any changes to the files in
your working directory as you like. When satisfied with your changes you
add any modified or new files to the staging area using add:
Adding files to the staging area
$ git add <filepattern>
Finally to commit the files in the staging area you run commit supplying
a commit message.
Committing staging area to the repository
$ git commit -m <msg>
Create an HTML file, add it, change it, and commit the change
$ ssh <id>@cs1520.cs.pitt.edu
$ cd public/csweb/git_example/
$ nano example.html #create a simple "Hello World" page
$ git add example.html #start tracking example.html
$ git commit -m "adding the first file to the repo"
$ nano example.html #change the page a bit
$ git add example.html #stage the file for commit
$ git commit -m "small update to example.html"
In this class, you will have to submit your assignments using Git.
The submission directory for each student is:
/afs/pitt.edu/home/n/l/nlf4/submissions/cs1520/<id>/<assignment>/
˜nlf4/submissions/cs1520/<id>/<assignment>/
For this exercise, I’ve made an ”example” assignment, so you can submit
your git example repository (containing example.html) by cloning the
repository in the submission directory a follows (from cs1520.cs.pitt.edu):
You may want to work on your code and projects from your own laptop
or desktop. Instructions for installing Git on various platforms (Linux,
OSX, Windows) can be found in the Book Pro Git:
http://git-scm.com/book/en/Getting-Started-Installing-Git
On Linux and OSX, you can simply open up a terminal and start using
Git.
On Windows, you’ll have to navigate to an appropriate directory, right
click, and then open up a Bash shell to use msysGit.
http://git-scm.com/downloads/guis
You’ve now cloned two working repositories from the bare repository.
To share your commits with the remote you invoke the push command:
Pushing local commits to the remote
$ git push
To recieve changes that other people have pushed to the remote server
you can use the pull command:
Pulling remote commits to the local working directory
$ git pull
Git is a powerful and flexible DVCS. Some very useful, but a bit more
advanced features include:
Branching
Merging
Tagging
Rebasing
GitHub
$ git clone git://github.com/askielboe/into-to-git-slides.git
I’m hosting the LATEX-source for these slides within the CS dept.