Git – A Quick Reference

# Starting a git repository
git init

# Creating a working copy of a repository (Check-Out)
git clone /path/to/repository

# Creating a working copy from a particular branch of a repository (Check-Out)
git clone -b feature/branchName /path/to/repository

# Switching to another branch of a repository
git switch feature/branchName

# Get current branch status
git status

# Adding a file to Index (Check-In)
git add path/fileName.extension

# Adding all the files to Index (Check-In)
git add –all

# To commit the changes
git commit -m “Commit Message”

# Pushing changes from the HEAD of your local working copy to remote repository
git push

# If a file was added to the stage by mistake then undo a stage
git reset path/fileName.extension

# Another way to undo the staging changes
git restore –staged path/fileName.extension

# Reseting code by deleting all changes. HEAD is the latest local commit
git reset –hard HEAD

# Same as above but N commits back.
git reset –hard HEAD~N

# Reset code but keep changes locally. (Useful for uncommiting a not pushed mistake)
git reset –soft HEAD~1 [Tip: Use HEAD~2 if a merge occured]

# Save local uncommitted changes temporarily
git stash

# Bring back the saved changes
git stash apply

# Getting repository history
git log

# To see the fileName of committed changes
git show –pretty=”” –name-only

# To see the contents of committed changes
git show

# Downloads new changeSet from a remote repository but don’t integrate to working files
git fetch

# Downloads new changeSet from a remote repository
git pull

# Getting the list of all branchs at local with their respective origins
git branch -lvv

# Getting the difference between two files
git diff HEAD: path/fileName.extension path/fileName.extension

# Setting the proxy
git config –global http.proxy http://website.proxy.com:9090
git config –global https.proxy http://website.proxy.com:9090

# Getting help for Git commands
git –help

Leave a comment