git-guide/cheat-sheet.md

1.4 KiB

Git Cheat Sheet

Here are a collection of useful git commands covered in this guide so far:

Clone a Repository

# Use SSH if you want to commit back HTTPS is fine for cloning
git clone <REPOSITORY_URL>

Stage Changes for Commit

# Add a single file

git add <FILE>

# or add all files

git add .

Commit Changes

# See a log and edit message in editor

git commit -a

# Add message on command line

git commit -m "Commit message"

Push Changes to the Remote Repository

git push

Create a New Branch

git branch <BRANCH>

Switch to a Different Branch

git checkout <BRANCH>

Merge Changes from Another Branch

# First check out to the target branch
git merge <BRANCH>

Other useful commands

Look at the git log

git log

Stash changes

Removes your changes and takes you back to the original state of the repo

git stash