ctrl + f or cmd + f to search what you need instantly
GIT is a version control system (VCS)
Code history
Snapshots of files
"commit" take a snapshot
3 tier configuration in git
Local Highest priority
Global
etc
Basic commands
# Initialise Local Git Repository
$gitinit
# Add files
$gitadd<file>$gitadd*.<fileextension>// add all files with the .<file extension>$gitadd.// add all files
# Remove files
$gitrm<file>
# Check status of working tree
$gitstatus
# Commit changes to index
$gitcommit$gitcommit-m"Commit Message"
# Push commits to remote repository
$gitpush
# Pull lastest from remote repository
$gitpull
# Clone Remote Repository into a new Local directory
$gitclone
# Branch
$gitbranch// Shows the branches of the repository$gitbranch<branchname>// Create <branch name>$gitbranch-D<branchname>// Deletes the branch$gitcheckout// Switch branch$gitcheckout-b<branchname>// Create and switch to <branch name>
Helpful Commands
### (5 commits ago) HEAD~5 || "HEAD^^^^^"
## Anything that can be parsed, a branch, a head, a tag, a hash
# rev-parse
$gitrev-parse<branch>// return current commit hash
Advanced Commands
# Display Commit(s) history of repository
$gitlog$gitlog--stat// Show files$gitreflog// in order of last referenced
# Show changes between commit
$gitdiff$gitdiff<commithash1><commithash2>
## --amend (changes git history) -> only use before pushing
# Change last commit message
$gitcommit--amend-m"New Commit Message"# Add files to last commit
$gitcommit--amend
## cherry-pick (move commits to other branch, don't delete commits)
$gitlog// get the commit hash [7 - 8] characters$gitcheckout<branchname>$gitcherry-pick<commithash>
## Delete commit
# --soft :: reset back to commit specified, keep changes made in staging dir
$gitreset--soft<commithash># (default, mixed) keeps changes in working dir
$gitreset<commithash># --hard :: reverts all track files, not untracked files
$gitreset--hard<commithash>
# Delete untracked files
$gitclean-df// d - directory, f - files
[a32][a23]|\(branch)|[2e2][d19][2e2]|||[8b3][e69][8b3]\(branch)[d19']|[e69']# Rebasing (fast forward merge)
$gitrebasemaster// might mess up reflog# interactive rebase (can't rebase commits thats shared)
$gitrebase-iHEAD~2(2commitsago)/* vim will pop up */
Unconventional Hipster Cool Commands
*Below shows the hardest way to create a file
How git commit works:
commit -> tree -> blob (file)
## Revert changes (doesn't modify commit history)
# Show changes between commit
$gitrevert<commithash>
## writing into file
# hash-object
$echo"new file."|githash-object-w--stdin// it returns a hash
## print from hash
# cat-file
$gitcat-file-p<filehash>$gitcat-file-t<hash>// t - type
## update staging area
# update-index
$gitupdate-index--add--cacheinfo<filepermission><filehash><filename.ext>
## tree object
# write-tree
$gitwrite-tree// it returns hash of a tree object$gitcat-file-p<treehash>// returns directory listings$gitcommit-tree<treehash>-m"Commmit message"// returns a commit hash
## cat .git/HEAD
# update-ref
$gitupdate-refrefs/heads/<currentbranch><commithash>// it updates ref
## actual file
# checkout HEAD
/*
* -- seperates all option switches and parameters
* from a list of files
* works for diff , checkout
*/$gitcheckoutHEAD--<file.ext>//