Igor Khromov blog

Git commands cheat sheet

Configuration

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
git config --global core.editor "nano"

Create repository

git init <directory>   // create a new Git repository

Clone repository

git clone <repository> // clone an existing Git repository

Basic Workflow

git status                 // check the status of the repository
git add <file>             // stage a file for commit
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

Branches

git branch                  // list all branches
git branch <branchname>     // create a new branch
git checkout <branchname>   // switch to a branch
git merge <branchname>      // merge a branch into the current branch
git push origin <branchname>// push changes to a branch on the remote repository
git pull origin <branchname>// pull changes from a branch on the remote repository
git branch -d <branchname>  // delete a branch                   // pull changes from a remote repository

Logs

git log                  // show commit history
git log --graph          // show commit history as a graph
git log --author=<name>  // show commit history by author
git log --oneline        // show commit history in one-line format

Tags

git tag                 // list all tags
git tag <tagname>       // create a new tag
git tag -a <tagname> -m "Message" // create an annotated tag with a message
git push origin <tagname> // push a tag to the remote repository
git push --tags          // push all tags to the remote repository