Git CheatSheet

#set a name that is identifiable for credit when review version history
$ git config --global user.name “[firstname lastname]"

#set an email address that will be associated with each history marker
$ git config --global user.email “[valid-email]”

#initialize an existing directory as a Git repository
$ git init 

#retrieve an entire repository from a hosted location via URL
$ git clone [url] 

#show the commit history for the currently active branch
$ git log 

#show the commits on branchA that are not on branchB
$ git log branchB..branchA 

#show the diff of what is in branchA that is not in branchB
$ git diff branchB...branchA

# list your branches. a * will appear next to the currently active branch
$ git branch

#create a new branch at the current commit
$ git branch [branch-name] 

#switch to another branch
$ git checkout 

#merge the specified branch’s history into the current one
$ git merge [branch]

#Shows the status of file either staged or not
$ git status 

#add a file so that it can be added to staged area in next commit, if we pass dot (.) as file name then all all files in present directory will be a
$ git add [file] 

#unstage a file while retaining the changes in working directory
$ git reset [file] 

#difference of what is changed but not staged
$ git diff

#diff of what is staged but not yet commited
$ git diff --staged 

#add a git URL as an alias
$ git remote add [alias] [url] 

#fetch down all the branches from that Git remote
$ git fetch [alias] 

#Push local branch commits to the remote repository branch
$ git push [alias] [branch] 

#fetch and merge any commits from the tracking remote branch
$ git pull 

#delete the file from project and stage the removal for commit
$ git rm [file] 

#change an existing file path and stage the move
$ git mv [existing-path] [new-path] 

#show all commit logs with indication of any paths that moved
$ git log --stat -M 

#apply any commits of current branch ahead of specified one
$ git rebase [branch] 

#clear staging area, rewrite working tree from specified commit
$ git reset --hard [commit] 

#save modified and staged changes
$ git stash

#list stack-order of stashed file changes
$ git stash list 

$ git commit -m "empty commit" --allow-empty




DevOpsMap

Learn today for better tomorrow

0 Comments