0% found this document useful (0 votes)
4 views3 pages

Github Git Cheat Sheet

This GitHub/Git Cheat Sheet provides a quick-reference guide for essential Git commands related to setting up identity, cloning repositories, managing branches, and pushing changes. It includes instructions for common workflows, such as updating, merging, and temporarily saving changes. Additionally, it emphasizes the importance of checking the current status to prevent conflicts and data loss.

Uploaded by

Hossein Najafi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Github Git Cheat Sheet

This GitHub/Git Cheat Sheet provides a quick-reference guide for essential Git commands related to setting up identity, cloning repositories, managing branches, and pushing changes. It includes instructions for common workflows, such as updating, merging, and temporarily saving changes. Additionally, it emphasizes the importance of checking the current status to prevent conflicts and data loss.

Uploaded by

Hossein Najafi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

GitHub / Git Cheat Sheet

A practical quick-reference for updating, branching, committing, pushing, and managing GitHub repositories.

Setup Git identity


git config --global [Link] "Your Name"
git config --global [Link] "your@[Link]"
Description: Sets your name and email for commits on this computer.

Clone a repo
git clone [Link]
cd repo
Description: Downloads a GitHub repository to your computer and moves into the project folder.

Check current status


git status
Description: Shows your current branch, changed files, staged files, and whether you are ahead or behind the remote.

Get latest changes


git pull
Description: Downloads and applies the newest changes from the remote branch into your current branch.

Safer update workflow


git fetch
git status
git pull
Description: Fetches remote changes first, lets you inspect your state, then pulls when everything looks safe.

Create a new branch


git checkout -b new-branch-name
Description: Creates a new branch and switches to it immediately.

Switch branch
git checkout main
# or
git switch main
Description: Moves you from your current branch to another existing branch.

Stage and commit changes


git add .
git commit -m "Your commit message"
Description: Stages your edited files and saves them as a new commit with a message.

GitHub / Git Cheat Sheet Page 1


Push changes to GitHub
git push
Description: Uploads your local commits to the connected GitHub remote branch.

First push for a new branch


git push -u origin new-branch-name
Description: Uploads a new local branch to GitHub and links it to the remote branch for future pushes.

See local branches


git branch
Description: Lists branches available on your computer and marks the branch you are currently using.

See remote branches


git branch -r
Description: Lists branches that exist on the remote repository, such as GitHub.

Merge a branch into main


git checkout main
git pull
git merge branch-name
Description: Switches to main, updates it, then combines another branch into main.

Discard changes in one file


git checkout -- file-name
Description: Restores one file to its last committed version and removes your local edits.

Discard all local changes


git reset --hard
Description: Deletes all uncommitted local changes and resets the repo to the last commit.

Temporarily save changes


git stash
git pull
git stash pop
Description: Saves your unfinished work temporarily, updates the repo, then reapplies your work.

See commit history


git log
# short version
git log --oneline
Description: Shows previous commits; the one-line version is easier to scan.

GitHub / Git Cheat Sheet Page 2


Connect local repo to GitHub
git remote add origin [Link]
git branch -M main
git push -u origin main
Description: Links a local project to a GitHub repo, renames the main branch, and pushes it online.

Common feature workflow


git checkout main
git pull
git checkout -b my-feature
# make changes
git add .
git commit -m "Add my feature"
git push -u origin my-feature
Description: Updates main, creates a feature branch, commits your work, and pushes it so you can open a Pull Request.

Tip
Before pulling or switching branches, run git status. It helps you avoid losing work or creating conflicts.

GitHub / Git Cheat Sheet Page 3

You might also like