Skip to content

Instantly share code, notes, and snippets.

@patricktouchette
Created July 10, 2019 18:33
Show Gist options
  • Save patricktouchette/95baf688d480e0cdad348323c55f5078 to your computer and use it in GitHub Desktop.
Save patricktouchette/95baf688d480e0cdad348323c55f5078 to your computer and use it in GitHub Desktop.
Git Cheat Sheet

Install Git

go to https://git-scm.com/

download and install

git --version

Help

git help config

git config --help

Set Config Values

git config --global user.name "Patrick Touchette"

git config --global user.email "pat@gitmail.com"

git config --list

Initialize a Repository

git init

git status

touch .gitignore

Add files to staging area

git add -A
git add .

Remove files from staging area

to remove all files

git reset

to remove a specific file

git reset file.js

Commit

git commit -m "detailed message"

Summary

git init
touch .gitignore
touch readme.md
git add .
git commit -m "first commit"

Cloning a remote repo

git clone <url> <where to clone>

git clone ./path/to/remote/remote.git .

View information about the remote repository

git remote - v

To see all the branches

git branch -a

Pushing changes

commit changes

git diff
git status
git add -A
git commit -m "modified a function"

then push

git pull origin master
git push origin master

Create a branch for a desired feature

git branch mybranch
git checkout mybranch

to check out which branch you are in

git branch

Write code for that feature then commit

git commit .

After commit push branch to remote

git push -u origin mybranch

check that the branch was added to remote

git branch -a

Merge a branch

git checkout master
git pull origin master

Check wich branches have been merged

git branch --merged

Merge the branch

git merge mybranch

Push to remote repo

git push origin master

Deleting a branch

check the branches

git branch --merged

delete branch locally

git branch -d mybranch

git branch -a

delete branch from the remote

git push origin --delete mybranch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment