Contains all data and metadata for the git version control system
git init
git clone [path-to-repository]
*
Staging area is also known as the "index"
git config --global user.name "Shantanu Goel"
git config --global user.email "[email protected]"
git status -s
git diff
git diff [filename]
git add [filename]
# Stage all files under current path
git add .
# See diff of staged files
git diff --cached
git commit
# Add all tracked files without needing a git add step and
# specify a short commit message with the command itself
git commit -am
git log
git log --oneline --graph
git push [repository] [branch]
git push origin master
git pull
git branch
git checkout [branch-name]
git checkout -b [branch-name]
git merge [branch-to-merge]
git branch -d [branch-name]
git rebase
git rebase -i
Unimpacted content
< source-branch
Conflicting code from source branch
========
Conflicting code from feature branch
# Conflicts fixed, continue rebasing
git rebase --continue
# Abort rebasing
git rebase --abort
# Skip this commit
git rebase --skip
git cherry-pick [commit-hash-to-pick]
# Save current staged and unstaged changes into a hidden location
# and remove them from the working directory
git stash
# Bring back stashed changes
git stash pop
git checkout [commit-hash]
git checkout -- [file-name-or-path-or.]
git revert [commit-hash]
# Reset the head of current branch to given reference
# Move the index as well to this reference
# The changes after the above reference show up as unstaged
# No loss of staged/unstaged changes or other commits
git reset --soft [ref]
# Reset the head of current branch to given reference
# The changes after the above reference show up as staged
# No loss of staged/unstaged changes or other commits
# --mixed is the default mode of reset if you don't specify any option
git reset --mixed [ref]
# Reset the head of current branch to given reference
# All staged/unstaged changes and other commits are removed
# Potential recovery possible (shown in further slides)
# But make sure no unstaged changes present before running this
git reset --hard [ref]
# Init repo
repo init -u url
# Sync all working directories and rebase branches
repo sync
# Download a specific patch from gerrit
repo download
# Check status of all changes across all projects
repo status