Show Menu
Cheatography

git_commands_cheat_sheet Cheat Sheet by

This cheat sheet contains commands for using git

git commands for version tagging

git tag
List all available tags in Git
git tag -l [tag_n­umber]
search for tags with the particular tag_number
git tag -a [tag_n­umber] -m [message]
creates an annotated tag with an optional tagging message
git show [tag_n­umber]
shows the tagger inform­ation
git tag [tag_n­umb­er]-lw
creates a lightw­eight tag
git tag -a [tag_n­umber] [part_­of_­che­ck_sum]
tags the commit after you've moved passed them
git push origin [tag_n­umber]
push versio­n_n­umber to shared server after you have created them.
git push origin --tags
push tags to shared server
git checkout -b [branc­h_name] [tag_name]
put a version of the repository in your working directory that looks like a specific tag
By default, the git push command doesn't transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches, you can run git push origin "­tag­_na­me"

git commands to clone and create reposi­tories

git init
Initia­lizes a new git repository in the current directory
git clone url
Clone an existing Git repository located at in the current directory
git clone url direct­ory­_name
Clone an existing Git repository located at in direct­ory­_name

git commands to check status

git status
used to determine which files are in which state
git status -s
the short and compact repres­ent­ation of git status

git commands for removing and renaming files

git rm "­fil­e_n­ame­"
Removes the file from your tracked files and the working directory
git rm --cached "­fil­e_n­ame­"
Removes the files from your tracked files but keeps the file in the working directory
git mv "­fil­e_f­rom­" "­fil­e_t­o"
Renames the file form "­fil­e_f­rom­" to "­fil­e_t­o"

git commands for undoing things

git reset [file_­name]
used to unstage the "­fil­e_name
git checkout -- [file_­name]
reverts a file to the previous version

git commands for staging files

git add file_name
Stage file_name for commit
git add -A
Stage all modified or new files for commit
git reset file_name
Unstage file_name

git commands for working with remotes

git remote add "­nam­e" "­url­"
Create a new remote named "­nam­e" for the repository at "­url­"
git fetch "­rem­ote­"
Download all changes from "­rem­ote­", but don't integrate into current branch
git merge "­rem­ote­"­/"br­anc­h"
Merge "­rem­ote­]/[­bra­nch­" into current branch
git push "­rem­ote­" "­bra­nch­"
Push local changes in "­bra­nch­" to "­rem­ote­"­/"br­anc­h"
git pull "­rem­ote­" "­bra­nch­"
Fetch and merge all changes from "­rem­ote­"­/"br­anc­h" into current branch
 

git commands for commiting changes

git commit -m "­mes­sag­e"
Commit staged changes with "­mes­sag­e" describing changes
git commit --amend
Edit the previous commit message or contents
git commit -a -m "­mes­sag­e"
Stages all already tracked files and commits them

git commands for branching and merging

git remote add "­nam­e" "­url­"
Create a new remote named "­nam­e" for the repository at "­url­"
git branch "­nam­e"
Create a new branch named "­nam­e"
git checkout "­nam­e"
Switch to branch named "­nam­e"
git merge "­bra­nch­"
Merge "­bra­nch­" into current branch
git merge --no-ff "­bra­nch­"
Merge "­bra­nch­" into current branch, keeping branch history

git commands for inspec­tions and differ­ences

git log
View the commit history of the current branch
git log "­bra­nch­"
View the commit history of "­bra­nch­"
git log --stat
Prints below each commit entry a list of modified files, how many files where changed, and how many lines in those files where added or removed
git log --pret­ty=­online
This option changes the log output to formats other than the default
git log --graph
Display an ASCII graph of the branch and merge history beside the log output
git diff
View unstaged changes between the current state of the code and the last commit
git diff --cached
View staged changes between last commit and the current state of the code
git diff "­bra­nch­1" "­bra­nch­2"
View differ­ences between "­bra­nch­1" and "­bra­nch­2"
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Git Cheat Sheet