DEV Community

RaShunda Lanier
RaShunda Lanier

Posted on

GIT Cheatsheet

Here's a git cheat-sheet that covers some of the most commonly used git commands:

Configuration

git config --global user.name "Your Name"
Enter fullscreen mode Exit fullscreen mode
  • Sets your name for all git repositories on your computer
git config --global user.email "youremail@example.com"
Enter fullscreen mode Exit fullscreen mode
  • Sets your email address for all git repositories on your computer
git config --global color.ui auto
Enter fullscreen mode Exit fullscreen mode

Enables colored output in the terminal

Creating a repository

git init
Enter fullscreen mode Exit fullscreen mode

: Initializes a new git repository in the current directory

git clone <repository_url>
Enter fullscreen mode Exit fullscreen mode

: Clones an existing repository from a remote server to your local machine

Staging changes

git add <file>
Enter fullscreen mode Exit fullscreen mode

: Adds a file to the staging area

git add .
Enter fullscreen mode Exit fullscreen mode

: Adds all changed files in the current directory to the staging area

Committing changes

git commit -m "Commit message"
Enter fullscreen mode Exit fullscreen mode

: Commits the staged changes with a message describing the changes made

Branching

git branch: Lists all local branches
git branch : Creates a new branch
git checkout : Switches to a different branch
git merge : Merges changes from the specified branch into the current branch

Remote repositories

git remote add : Adds a new remote repository
git push : Pushes changes to the specified branch in the remote repository
git pull : Pulls changes from the specified branch in the remote repository

Viewing information

git status: Shows the status of the current branch and any changed files
git log: Displays a log of all commits on the current branch
git diff: Shows the differences between the working directory and the staging area
git diff --staged: Shows the differences between the staging area and the last commit

Top comments (0)