Installation
For Linux, the required packages are « git-core » (the real package) and « gitk » (graphical interface).
sudo apt-get install git-core gitk
For Mac Os X, you can use the installer from here.
Configuration
Activate the color in Git : your messages will be more readable.
git config --global color.diff auto git config --global color.status auto git config --global color.branch auto
Now, you have to configure your name and your email
git config --global user.name "your_pseudo" git config --global user.email my_email@domain.com
All these informations are in the ~/.gitconfig file. You can add some aliases at the end. The aliases allow you to put a shortcut for git commands.
[color] diff = auto status = auto branch = auto [user] name = votre_pseudo email = moi@email.com [alias] ci = commit co = checkout st = status br = branch
Getting started
- Create a new rep
Create a new directory (for example : /home/jerome/workspace/my_project/). With your console, go in your directory and type
git init
This will create an hidden directory .git
- Clone an existing rep
In this case, we are gonna clone a repository from GitHub (for example : http://github.com/symfony/symfony.git).
git clone http://github.com/symfony/symfony.git
Methodology
- Modify the source code
- test if your app is still working
- make a commit to save the changes and let know Git
- restart to step 1
The following command line will give you the modified files of your project.
git status
To see the differences, type
git diff src/Symfony/Components/Yaml/Yaml.php
Make a commit
You must specify the file you want to commit. Making a git status
will mark your modified files in red. They will not be taken into account during the commit.
git add file1 file2
: this add the files for the « to commit » list. Then you have to make agit commit
. Used when you create new files Git doesn’t know.git comment -a
will commit all the files (Changes to be committed and Changed but not updated). Used to save all the changes you’ve made.git commit file1 file2
indicate the files and commit them. Used to commit specific files.
When a commit is done, vim or nano open. You have to write a message describing your changes.
All these commit are local. Except if you send the commit to the server (we will see that later). For the moment, you can cancel your last commit.