What is git?
Git is a version control system. While there are numerous uses for git, we highlight using it to manage the changes you make to your project. Check out the links at the bottom for some more ideas and uses for git.
Git stores everything in a git repository. To retrieve a git repository, there are two options. You can either initialize a new repository in a project’s directory or you can clone one from a public git repository.
Initialize a new repository
To create a repository for an existing directory of files,
cd into the home directory of your project and initialize the repository:
Clone an existing repository
To create a copy of an existing project, run the
git clone command with the URL for the project you want
git clone git://github.com/radiant/radiant.git
Working in the repository
Think of git as taking snapshots of your files. You can edit and manipulate your files to how you want them, then you can send them to the staging area, and then you can take a snapshot of these files.
To add a list of files (README and test.rb) you can use:
git add README test.rb
Or you can add all files in the directory:
git add .
Lastly, you want to commit the code to the repository:
git commit -m 'first commit'
-m option allows you to append a message with the commit. Preferably something useful so that you can know what that commit is about.
To view the status of your files in your directory:
This tells you what files have been modified since the last time they were committed.
A great tool to use is a git history viewer. Git comes in with a built in viewer. If you
cd into your repository and run the
gitk command, you are presented with a nice GUI to view your git history. This is a very barebones viewer. If you want to have one that feels more native to your OS and have some more functionalities, look at GitX for Mac and tortoisegit for Windows.
- GitHub Help Section
- Git Reference Site
- VIDEO: Railscasts on Git
- VIDEO: PeepCode on Git
- BOOK and VIDEO: Getting Good with Git
If you have feedback or questions about this page, add a comment below. If you need help, submit a ticket with Engine Yard Support.