git --version
: Check the versiongit help
: Get help from gitgit help commit
: Get help for the commit commandgit config
: Get information about configurationgit config --list
: Check all configurationsgit config --global user.name "username"
: Configure git user namegit config --global user.email "email"
: Configure git user email
git init
: Initialize git repository on the local machinegit status
: Check changes or status of files in the repository
git add filename1.txt
: Add only one filegit add filename1.txt filename2.txt
: Add multiple filesgit add .
: Add all files and folders to the staging area
git commit -a
: Stage and write a commit message in Nanogit commit -m "commit message"
: Write a commit message after staginggit commit -am "commit message"
: Stage and commit everything in one step
git log
: See the history of the repositorygit log --oneline
: View history in one linegit log -<limit>
: Limit the number of log entriesgit log --author="name"
: Check changes by a specific usergit log --graph
: Visualize the history
git diff
: Compare working copy with the repositorygit diff --staged
: Compare files in the staging area
git checkout -- filename
: Retrieve working copygit reset HEAD filename
: Unstage changesgit checkout <branch-name> <path to file>
: Checkout file from a different branchgit checkout <commit-id> -- <path to file>
: Checkout file from a specific commit
git remote -v
: View remote repository URLsgit remote add <remote name> repository-Url
: Add a new remotegit push -u remote master
: Push the files to GitHub
git rm filename1
: Delete one tracked filegit mv filename1 filename2
: Rename a filegit mv filename1 foldername/filename1
: Move file to a folder
git branch
: List branchesgit branch branch-name
: Create a branchgit checkout branch-name
: Switch to a branchgit checkout -b branch-name
: Create and switch to a new branchgit merge branch-name
: Merge a branch into the current branch