This article gives the basics for a beginner user who needs to start tracking and contributing to projects managed with git.
The Git Repository
Initialising from an existing directory
git init
This command creates the .git directory.At this point nothing is tracked though.
git add *git add READMEgit commit -m 'Initial Commit'
Cloning an Existing Repository
Cloning pulls an existing repo from a remote location to your local machine. This is usually the case when you want to contribute to an open source project. Remember the entire history is cloned. The latest copy of the project is checked our into the working directory.
git clone https://github.com/yiisoft/yii.git yiimod
The above command clones the yii framework into a folder called yiimod in the current directory.
Recording Changes
Each file in your working directory is of a certain state: tracked or untracked.
Tracked Files: In previous repo snapshot as unmodified, modified or staged.
Untracked Files: Files not in last snapshot and not in staging area.
When you first clone a directory all files will be tracked and unmodified. When files are edited they become modified, they are staged and then commited.
Checking File Statii
git status
This command tells you what branch you are on and the statii of files.
Adding a new file to the repo will give a response of:
untracked files:
If you want to start tracking the newly added file you must explicitly:
git add <new file>
You must explicitly do so as it is possible that you application during compilation or runtime, additional unnecessary files were created.
Once you have added the file it is now staged as git status will give:
Changes to be commited:
If you modify a tracked file, without adding git status gives:
Changes not staged for commit:
This means the file is tracked and modified but not staged. If you add the modified file, the new file and modified file will show up under:
Changes to be commited:
new file: <new file>
modified: <modified file>
If you modify the <modified file> again, after git add, it will show up under both staged and unstaged changes. You will need to stage those unstaged changes.
Taken from: Pro Git