Skip to content

Latest commit

 

History

History
127 lines (120 loc) · 2.33 KB

File metadata and controls

127 lines (120 loc) · 2.33 KB

Git & GitHub Commands Cheatsheet 📋

⚙️ Setup & Configuration

Set your name for all commits:

git config --global user.name "[name]"

Set your email for all commits:

git config --global user.email "[email]"

Set the default branch name to 'main':

git config --global init.defaultBranch main

🚀 Starting a Project

Initialize a new local Git repository:

git init

Clone an existing repository from a URL to your local machine:

git clone [url]

💾 Making & Saving Changes

Show the status of changes as untracked, modified, or staged:

git status

Add a specific file to the staging area:

git add [file]

Add all new and modified files to the staging area:

git add .

Commit your staged changes with a descriptive message:

git commit -m "[message]"

View the commit history:

git log

🌱 Branches

List all local branches:

git branch

Create a new branch:

git branch [branch-name]

Switch to a different branch:

git checkout [branch-name]

Create a new branch and switch to it immediately:

git checkout -b [branch-name]

Merge the specified branch’s history into the current one:

git merge [branch]

Delete a local branch:

git branch -d [branch-name]

🌐 Syncing with Remotes

List all remote repositories:

git remote -v

Add a new remote repository:

git remote add origin [url]

Download all history from a remote repository without merging:

git fetch [remote]

Fetch and merge changes from the current branch's remote counterpart:

git pull

Push a specific branch to the 'origin' remote:

git push origin [branch]

📦 Stashing

Temporarily save modified, tracked files in order to switch branches:

git stash

Apply the most recent stash and remove it from the list:

git stash pop

List all stashed changesets:

git stash list

Discard the most recent stash:

git stash drop

⏪ Undoing Things

Unstage a file, but preserve its contents in the working directory:

git reset [file]

Discard all local changes in a specific file:

git checkout -- [file]

Create a new commit that undoes the changes from a specified commit:

git revert [commit-hash]