Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active February 13, 2024 23:41
Show Gist options
  • Save ross-u/2179208fa4378b86e7997700290e8f9a to your computer and use it in GitHub Desktop.
Save ross-u/2179208fa4378b86e7997700290e8f9a to your computer and use it in GitHub Desktop.
Git Basics - Cheat Sheet

Git Basics

Git commands - Cheat Sheet


Cloning the existing online repository

# FORK
# First Fork the repository you want to clone.
# This will create a copy on your GitHub that you will be allowed to change
# ...
# ...

# CLONE
# Copy the url of your repository copy and run the command
git clone <repository url>

# OPEN THE PROJECT
cd <project folder name>

code .

Creating commits

# git add <filename>
git add .


git status


git commit -m 'Initial commit'


git status


git push origin <branchname>

Initializing git in a new project

# Initialize git repository in the current project
# While in the root directory of your project
git init

# List all the files in the directory, this will show you .git directory
ls -a



# Create a connection between local and online repository
git remote add origin <github repo url>

# Check the list of repositories connected to local
# This will show the repo that we just connected to
git remote -v



# Check the status of the files in the project and the staging area.
git status

# Add all unstaged (red) files to the stagging area (prepare to commit)
# git add <filename>
git add .

# Check the status of the files and the staging area (stagged files are now green).
git status

# Create a commit (snapshot)
git commit -m 'Initial commit'

# Stagging area is now clear
git status


# Push code to the GitHub repository
git push origin <branch name>


# Check the history of all existing commits
git log


# Notice that each commit has a hash identifier
# Hash identifiers are used to move through to the history (by repointing the HEAD)

Connecting the local repository to the online (GitHub) repository

# First create the GitHub repository on the github.com
#  ...
#  ...

# Create a connection between local and online repository
git remote add origin <github repo url>

# Check the list of repositories connected to local
# This will show the repo that we just connected to
git remote -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment