Git Cheat Sheet

Find Useful Git commands in this Git Cheat Sheet.

Here is a basic Git cheat sheet:

git init - Initialize a new git repository

git clone [repository] - Clone an existing repository

git status - Check the status of your repository

git add [file] - Add a file to the repository

git commit -m "[message]" - Commit changes with a message

git push - Push changes to a remote repository

git pull - Pull changes from a remote repository

git branch - Show the current branch

git branch [branch-name] - Create a new branch

git checkout [branch-name] - Switch to a different branch

git merge [branch-name] - Merge a branch into the current branch

git log - Show the commit history

git diff - Show changes between commits

git reset --hard [commit] - Reset repository to a specific commit

git stash - Stash changes

git stash apply - Apply stashed changes

Please note that this is a basic cheat sheet and git has many more functionalities and options, it is worth reading the git documentation to learn more.


  • Clone a project:
    git clone git_repo_url project_name

  • Switch to a branch locally:
    git checkout branch_name

  • Modify a file, then save and push it to remote repo in current branch
    git add path_to_file_modifeid/file_name
    git commit -m "Description of modification"
    git push

  • Get a new version of a file after modifying local version
    git checkout path_to_file_modified/file_modified

  • Get latest version of current branch
    git fetch
    git pull
    if you have local changes, you will be prompted to commit or stash them before pulling.



  • Create a new branch based on current branch and switch to it
    git checkout –b branch_name

  • Switch to master branch
    git checkout master

  • Merge branch_name to master
    git merge branch_name

  • Delete local branch
    git branch -d branch_name

  • Undo a merge or pull
    git reset --hard

  • Undo a commit locally and on the remote branch
    git reset --hard commit_id
    git push --force

  • Get remote url of a local branch
    git remote show origin


Source: https://git-scm.com

← All articles