Git Cheat Cheet March 31, 2011
Posted by Tournas Dimitrios in Uncategorized.
Git is a very popular and efficient open source Distributed Version Control System (dvcs) written in C. A version control system allows that you can create a history for a collection of files with the possibility to revert them to another state. These collection of files is usually called “source code”. In a distributed version control system everyone has a complete copy of the source code (including the complete history of the source code) and can perform version control operations against this local copy. The usage of a dvcs does not require a central code repository .
This article is only a quick reference for the most used commands via the terminal (git bash not the Windows command line) , If you don’t already know what Git is, take a crash course.
Initializing and configuring
- Open the git bash terminal (not Windows command line !!! )
- Navigate to the directory where versioning will take place , enable git
=== or clone a project from Github ===
git clone git://github.com/someuser/projectname.git nameOflocalDir
- Show the current configurations
git config – -list
- Change Configuration settngs
git config – -global user.name yourUsername
git config – -global user.mail email@example.com
- Diff shows what is staged and what is modified but unstaged
git diff (modified files but not yet staged )
git diff – -cached (shows diff of staged files)
git diff HEAD ( shows diff of staged or unstaged files)
git diff – -stat (show summary of changes instead of full diff)
- In Git, you have to add file contents to your staging area before you can commit them. If the file is new, you can run git add to initially add the file to your staging area, but even if the file is already “tracked” – ie, it was in your last commit – you still need to call git add to add new modifications to your staging area. We can use git status to see what the state of our project is .Let’s see a few examples of this.
git status OR git status -s (“s” stands for short output)
git add filename
- Now that you have staged the content you want to snapshot with the git add command, you run git commit to actually record the snapshot. Git records your name and email address with every commit you make, so the first step ” Initializing and configuring ” from previous table is important .
git commit (It ‘ll ask you for a comment , it is a mandatory step )
git commit -m “Your comment” ( set your comment from the command line)
git commit -a (automatically stage all modified files and then commit)
- Unstage changes that you have staged
git reset HEAD – – filename
To be continued 🙂
- Download and install the latest version of msysgit (Windows)
- Tortoise git the graphical version of git
- Pro git the official on-line book of git
- Git ready –> lot of tutorial links
- Detailed instructions how to install git on Windows and enable ssh .
- For CentOs 5.5 , EPEL provides a ready made rpm file :
yum install git