Initializing/Cloning a new project and status commands
Command | Description |
---|---|
git init . |
Starting a new local git repository |
git clone <RURL>:<Repo> [--branch <BN> --single-branch] |
Coping the repository from remote server [for cloning only one branch] |
git status |
Show the working tree status |
git log |
Show commit logs |
git log --graph |
Draw a text-based graphical representation of the commit history |
git log --pretty=oneline --grep=search_term |
Make each commit on each line |
Configuration:
Command | Description |
---|---|
git config --global user.name "YOUR NAME" ; |
Set your name |
git config --global user.email "YOURSINGLE@gmail.com" |
Set your email |
git config --global color.ui true |
Color output |
git config --global credential.helper 'cache --timeout=3600' |
Cache your credentials for an hour |
git config --list |
List all configurations |
git config --global core.autocrlf true |
Handles cross platform line endings |
git config --global core.filemode false |
Ignore file permissions |
Adding and removing files from staging
Command | Description |
---|---|
git add . |
Add all files in the current folder to staging |
git add <FN> |
Add FN to staging |
git add -u |
Add all modified and deleted files to staging |
git rm <FN> |
Remove FN |
git add [-p|--patch] <FN> |
To add certain hunks (not all the file) to staged area. |
git diff --cached |
Show difference that is staged for the next commit |
git rm --cached <FN> |
Remove file from staged area |
git reset <FN> |
Removes staged changes |
git reset --hard <SHA1> |
Removes staged and working directory changes |
git checkout HEAD -- <FN> |
Checkout file from the last commit |
Commit changes
Command | Description |
---|---|
git commit |
Commit staged files |
git commit –a <FN> |
[-a] Add file then commit it, [-m] add comment in the command |
git commit –m "<COM>" |
Add all modified and deleted files to staging |
Branching
Command | Description |
---|---|
git branch |
List local branches |
git branch -r |
List remote branches |
git checkout –b <BN> |
Create a new branch and switching to the new branch |
git checkout <BN> |
Switch working directory to BN branch |
`git branch [-D | -d] ` |
git branch --track <BN> <RN>/<RBN> |
Create a new branch that tracks a remote |
Differences
Command | Description |
---|---|
git diff |
Show local changes |
git diff --stat |
Show files changed and number of lines changed |
git diff --cached |
Show difference that is staged for the next commit |
git diff master..<BN> |
Show difference between <BN> and master |
git diff master --stat |
Shows difference between current branch with master |
Merging
Command | Description |
---|---|
git merge <BN> |
Merge changes of <BN> with the current branch in a new commit object |
git rebase <BN> |
Add <BN> commits into the current branch commit history. |
git cherry-pick <SHA1> |
Apply the changes introduced by some existing commits |
Pulling and Pushing updates
Command | Description |
---|---|
git fetch [<RN>] |
Merge changes of <BN> with the current branch in a new commit object |
git pull [<RN>] |
Performs git fetch first then merges the remote changes to local branch |
git push [<RN> <RBN>] |
Apply the changes introduced by some existing commits |
Stashing
Command | Description |
---|---|
git stash |
Place current local changes in a stash |
git stash list |
List all stash stack items |
git stash pop |
Apply the changes of the top of the stack then drop it |
git stash apply stash@{0} |
Apply changes in a stash item |
git stash drop stash@{0} |
Delete stash item |
git stash clear |
Clear stash stack |
Git LFS Plugin
Command | Description |
---|---|
git lfs install |
After downloading the package from https://git-lfs.github.com install it. |
git lfs track ".model" |
Select type of fiels you want to use LFS to manage. |
git add .gitattributes |
Make sure to add .gitattributes, a file that keep track of LFS files. |
Convention:
Command | Description |
---|---|
<FN> | File Name |
<BN> | Branch Name |
<RBN> | Remote Branch Name |
<RN> | Remote Name |
<RURL> | Remote URL |
<Repo> | Repository Name |
<SHA1> | SHA-1 Hash |
<COM> | Comment |
[] | Optional parameter |
Book: https://progit2.s3.amazonaws.com/en/2016-03-22-f3531/progit-en.1084.pdf