Git and GitHub Cheat sheet

Git and GitHub Cheat sheet

What is Git?

Git is a version control system for tracking changes in source code during software development. It is mainly used to work in teams and can give a large number of people to contribute to a codebase.

What is GitHub

GitHub is one of the most popular online repositories which can be used to host source code.

git init

Initialize an existing directory as a Git repository

git clone [url]

Retrieve an entire repository from a hosted location via it's URL

git status

Show modified files in working directory, staged for the next commit

git add [file]

Add a file in it's current form now to the next commit (stage)

git reset [file]

Unstage a file while retaining the changes in working directory

git diff

Shows the difference of what is changed but not staged

git diff --staged

Shows the difference of what is staged but not yet commited

git commit -m “[descriptive message]”

Commit the staged content as a new commit snapshot

git branch

List all branches. A * will appear next to the currently active branch

git branch [branch-name]

Create a new branch at the current commit

git log

show all commits in the current branch’s history

git remote add [alias] [url]

add a git URL as an alias

git push [alias] [branch]

Transmit local branch commits to the remote repository branch

git pull

Fetch and merge any commits from the tracking remote branch

git reset --hard [commit]

Clear staging area, rewrite working tree from specified commit

git stash

Save modified and staged changes