Every programmer should know about VCS(Version Control System) especially GIT. This post serves as a short reference for most popular GIT commands. They are grouped by functionality and has a short explanation above them.To use them copy any command to your favorite command line tool.And if you wish to learn more about GIT check this out.
Table of Contents
First Steps
First thing which we have to do after installing GIT is to setup a name with an email and editor --global
option tells to set this variable in the~/.gitconfig
rather locally in .git/config
. Default is --local
which sets options for specific repository.
|
|
And if you would like to check already existing settings.
|
|
To get specific value.
|
|
To start track specific folder.
|
|
To clone remote repository.
|
|
If you need any help, these commands will open man page. verb is command’s name.
|
|
Information
GIT Commands used for getting any kind of information about repository.
STATUS
To check status of files
|
|
Short version of status
. Left column indicates status of the staging area and the right - working tree. M
stands for modified, A
stands for added, ?
- not tracked, !
- ignored files.
|
|
To show ignored files.
|
|
COMPARING
To compare files in working directory with staging area. Tells you what you changed but not yet staged.
|
|
To see what you staged which goes into your next commit. –staged and –cached are synonyms.
|
|
HISTORY
Outputs commit history.
|
|
Show difference in each commit.
|
|
Limit output to last entries.
|
|
Shows abbreviated stats.
|
|
Formats output. oneline
- single line, short
- adds extra info, full
- more info, fulller
- even more.
|
|
You can even format output.
|
|
Show output since 2 weeks.
|
|
INSPECTING
Show all blobs and trees where tree points to.
|
|
Show all blobs and trees recursively. t makes show the SHA-1s of the subtrees themselves, rather than just all the blobs.
|
|
Show what type object is. SHA-1 is an object hash.
|
|
Staging
Stage a file/files for commit.
|
|
To remove staged files, but keep it in the working directory.
|
|
To unstage file. Undoes any changes since last commit.
|
|
Interactive staging
|
|
Committing
To commit staged files.
|
|
To stage and commit shorthand.
|
|
Ammend last commit. For example change commit message or add extra files. It will overrides your last commit.
|
|
Branching
Create new branch. And switch to it.
|
|
Create new branch. And switch to it.
|
|
Create new branch and track to origin branch.And switch to it.
|
|
List all branches.
|
|
Delete a branch.
|
|
Delete remote branch.
|
|
Combining
Commands for merging and rebasing
MERGE
Merge a branch into current one.
|
|