Git Cheat Sheet
Below are some basic git commands
Basic Git Commands
-
$ git init
- Initialize local git repo... create .git folder in a project directory
-
$ git add < FILE NAME >
- Add file(s) to staging area of the index
-
$ git add .
- Adds all available files to staging area of the index
-
$ git status
- Check status of working tree
-
$ git commit
- Commit staged changes to local repository
-
$ git commit -m 'type a commit message here'
- Commit staged changes to local repository with message
-
$ git add README.md
- If you're going to add a README
Remote Repo Commands
-
$ git push
- Push to remote repository
-
$ git pull
- Pull latest from remote repo
-
$ git clone
- Clone repo into a new directory
-
$ git remote add origin < URL OF REMOTE REPO GOES HERE >
- Clone repo into a new directory
-
$ git push -u < REMOTE NAME > < BRANCH NAME >
- Clone repo into a new directory
Create a Branch
-
$ git branch < NAME OF NEW BRANCH >
- Creates a new branch in the repository
-
$ git checkout < NAME OF BRANCH >
- Switch to a different branch in the repository
-
$ git merge < NAME OF BRANCH > -m 'merge message'
- *FROM BRANCH MERGIN TO* Merges branch to another
Cloning
-
$ git clone < THE REPO URL >