Show Menu
Cheatography

A basic Git cheat sheet

Git : Configure

git config --global user.email "­you­rem­ail­@ex­amp­le.c­om­"
sets email address respec­tively to be used with your commits.
git config --global user.name "­Fir­stName LastNa­me"
sets the author name.
git config --list
command to list all the settings Git can find at that point.
git config --global color.ui true
Git automa­tically colors of its output.

Git : commit to repository

git commit -m "Add three files"
command records or snapshots the file perman­ently in the version history.
git commit --amend -m <enter your messag­e>
command allows you to change the commit message.

Git : branching

git branch
command lists all the local branches in the current reposi­tory.
git branch <br­anc­h-n­ame>
command creates a new branch.
git checkout <br­anc­h-n­ame>
command is used to switch from one branch to another.
git merge <br­anc­h-n­ame>
command merges the specified branch’s history into the current branch.
git checkout -b <br­anc­h-n­ame>
command creates a new branch and also switches to it.
 

Git : Initiating a repository

git init
command is used to start a new reposi­tory.
git status
command lists all the files that have to be committed.

Git : Pulling & pushing from and to reposi­tories

git remote add origin <li­nk-­to-­rep­o>
command is used to connect your local repository to the remote server.
git push -u origin master
command sends the committed changes of main branch to your remote reposi­tory.
git clone <li­nk-­to-­clo­ne-­rep­o>
command is used to obtain a repository from an existing URL.
git pull
command fetches and merges changes on the remote server to your working directory.

Git : Staging

git add <fi­le-­nam­e>
command adds a file to the staging area.
git add <fi­le-­nam­e> <se­con­d-f­ile­-na­me> <th­ird­-fi­le-­nam­e>
command adds one or more files to the staging area.
git add .
command adds all files under the current directory to the staging area.
git add --all
command finds all new and updated files everywhere throughout the project and add them to the staging area.
git add -A
Same as --all
git reset <fi­le-­nam­e>
command unstages the file, but it preserves the file contents
 

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
          Bash Dev Cheat Sheet