Handy guide to Git for software developers


Basics

# Initialise a Git Repo
git init

# Check the status of a Git Repo
git status

# Clone a repo
git clone <URL>

# Add a remote (for existing git repos)
git remote add origin <https://github.com/username/repository-name.git>

# Logs
git log --oneline

Staging

git add * # to add all changed files to the staging area
git add file.js # to add a specified file (recommended)

Commit

git commit -m "a commit message"

Take a look at semantic commit messages, a better way to write Git commit messages!

https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716


Branches

List all branches

git branches
git branches -r # for listing remote branches

Making a branch

git checkout -b canary
git push origin canary

Deleting a branch

git branch -d canary
git branch -D canary # Force Delete
git push origin :canary # Delete from remote

Update a branch

git pull # Local is behind remote, retrieve new commits from remote
git push # Push local changes to remote