gitconfig--globaluser.name"Your Name"# Set the global username for commitsgitconfig--globaluser.email"you@example.com"# Set the global email for commitsgitconfig--globalcore.editor"vim"# Set the default editor for Gitgitconfig--globalmerge.tool"vimdiff"# Set the default merge tool for Git
Getting Started
gitinit# Initialize a new Git repositorygitclone<repo># Clone an existing repository
Basic Commands
gitstatus# Show the status of the working directorygitadd<file># Add a file to the staging areagitadd.# Add all changes to the staging areagitcommit-m"message"# Commit changes with a messagegitcommit-am"message"# Add and commit tracked files with a messagegitdiff# Show changes between working directory and staging areagitdiff--staged# Show changes between staging area and last commitgitlog# Show commit historygitlog--oneline# Show commit history in one line per commitgitblame<file># Show who last modified each line of a filegitshow<commit># Show details of a specific commit
Branching and Merging
gitbranch# List branchesgitbranch<branch># Create a new branchgitcheckout<branch># Switch to a branchgitcheckout-b<branch># Create and switch to a new branchgitmerge<branch># Merge a branch into the current branchgitbranch-d<branch># Delete a branchgitbranch-D<branch># Force delete a branchgitlog--graph--oneline--all# Show branch and merge history
Remote Repositories
gitremote-v# List remote repositoriesgitremoteadd<name><url># Add a new remote repositorygitfetch<remote># Fetch changes from a remote repositorygitpull<remote><branch># Pull changes from a remote branchgitpush<remote><branch># Push changes to a remote branchgitremoterm<name># Remove a remote repository
Undoing Changes
gitcheckout--<file># Discard changes in working directorygitreset<file># Unstage a filegitreset--hard# Reset the working directory and staging area to the last commitgitreset--hard<commit># Reset the working directory and staging area to a specific commitgitrevert<commit># Create a new commit that undoes a specific commit