16Aug, 2018
0Comments

GIT CHEAT SHEET

CREATING A REPOSITORY

  • $ git init [project_name]

DOWNLOAD AN EXISTING REPOSITORY

  • $ git clone myurl
  • $ git status

OBSERVE YOUR REPOSITORY

  • List new or modified files which are not yet committed
    $ git status
  • Show all staged and unstaged file changes
    $ git diff HEAD
  • Show the changes between two commits ids
    $ git diff commit 1 commit 2
  • List the change dates and authors for a file
    $ git blame [file]
  • Show the file changes for a commit id and/or file
    $ git show [commit] : [file]
  • Show full change history
    $ git log
  • Show change history for file/directory including diffs
    $ git log -p [file/directory]

WORKING WITH BRANCHES

  • List all local branches
    $ git branch
  • ist all branches, local and remote
    $ git branch -av
  • Switch to a branch, my_branch, and update the working directory
    $ git checkout my_branch
  • Create a new branch called new_branch
    $ git branch new_branch
  • Delete the branch called my_branch
    $ git branch -d my_branch
  • Merge branch_a into branch_b
    $ git checkout branch_b
    $ git merge branch_a
  • Tag the current commit
    $ git tag my_tag

MAKE A CHANGE

  • Stages the file, ready for commit
    $ git add [file]
  • Stage all changed files, ready for commit
    $ git add .
  • Commit all staged files to versioned history
    $ git commit -m “Commit Message”
  • Commit all your tracked files to versioned history
    $ git commit -am “commit message”
  • Unstaged file, keeping the file changes
    $ git reset [file]
  • Revert everything to the last commit
    $ git reset –hard

SYNCHRONIZE

  • Get the lastly done changes from origin (no merge)
    $ git fetch
  • Fetch the lastly done changes from origin and merge
    $ git pull
  • Fetch the last changes from origin and rebase
    $ git pull –rebase
  • Push local changes to the origin
    $ git push

& FINALLY

  • When in doubt, use git help
    $ git command –help

WRAPPING UP

These Git commands will cover the entire range of Git functions. Though it is quite difficult to remember all the Git commands, so the best and easy way is to use this Git cheat sheet while working on complicated projects. If you think we have missed out any important command then do let us know in the comment below.

Post A Comment

Your email address will not be published. Required fields are marked *