Show Menu
Cheatography

Git Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

About Git

Git vs other systems
The major difference between Git and any other VCS (Subve­rsion and friends included) is that they store as a set of files and the changes made to each file over time. Git thinks about its data more like a stream of snapshots.
Git states
Git has three main states that your files can reside in: 1) committed, 2) modified, and 3) staged:
* Committed means that the data is safely stored in your local database.
* Modified means that you have changed the file but have not committed it to your database yet.
* Staged means that you have marked a modified file in its current version to go into your next commit snapshot (staging area).
Getting Help
git help <ve­rb>
man git <ve­rb>
git add -h
or
git add --help
ex:
git help config

.git folder

About
A folder to save history and version control inform­ation about the project

Config

show the git config info
git config --list
add user name (use --global for global change in system)
git config [--global] user.name "­­[n­a­m­e]­­"
add user email (use --global for global change in system)
git config [--global] user.email "­­[email addres­­s]­"
Set editor
git config --global core.e­ditor nano
Checking git setting
git config --list
git config user.name
> John Doe
Git config files
Stores in 3 level: 1) system config files 2) user specific config file 3) repository config file
1) System config file: located at /etc/g­itc­onfig. can change if you pass
--system
option to
git config
command
2) user config file: /.gitc­onfig or /.conf­ig/­git­/co­nfig. Can change if you pass
--global
option to
git config
command.
3) Repository config file: .git/c­onfig. Can change if no other option is specified or
--local
option is set.

Staging

Get staging status
git status
"Get inform­ation about files that have special status to get. Not previo­usley added and commited files."­
Staging Area
 

Commit

Commit all files in the staging area into local reposi­­tory
using editor­(co­mmand and then save commit message inside editor):
git commit
Commit with inline message
git commit -m "­­commit messag­­e"
Commit with all the changes that it can find (from tracked files)
git commit -a

Add file

Add file from workspace into staging area
git add <fi­­le­1> <fi­­le­2> ...
Add all files from current dir into staging area
git add .
Add all tracked file and untracked file from the workspace into staging area
git add -A .
Add using Regular expression
git add *.js

Create­/Remove a repository

Init­i­alize the current dir to be reposi­­tory
cd <pr­­oj­e­c­t_­­dir>
git init
touch README
Init­i­alize given dir to be reposi­­tory
git init my_rep­ository
From other reposi­tories
git clone exist­­ing­­_dir new_dir
git clone git:/­­/gi­­th­u­b.c­­om/­­us­e­r­/r­­epo.git
git clone https­­://­­gi­t­h­ub.c­o­­m/u­­se­r­/­re­­po.git
Remove the repository
rm -r reposi­tor­y_f­old­er/.git