Git Cheat Sheet for GitHub

Setting Up & Configuration

git config --global user.name "Your Name" – Configure user information for all local repositories

git config --global user.email "youremail@example.com"

git init – Initialize a new git repository

git clone https://github.com/username/repo-name.git – Clone an existing repository

Basic Git Workflow

git status – Check the status of your files

git add filename – Track new files

git commit -m "Commit message" – Commit changes in tracked files

git push origin branchName – Push changes to GitHub

git pull – Pull latest changes from GitHub

Branching & Merging

git branch branchName – Create a new branch

git checkout branchName – Switch to a branch

git merge branchName – Merge a branch into the active branch

git branch -d branchName – Delete a branch

Viewing Changes

git diff – View changes

git log – View the commit history

Undoing Changes

git checkout -- filename – Undo modifications to a file

git reset HEAD filename – Remove changes from the staging area

git revert commitHash – Revert a commit by creating a new commit with opposite changes

git reset --hard commitHash – Reset your HEAD pointer to a previous commit

Tagging

git tag – List all tags

git tag tagName – Create a new lightweight tag

git tag -a tagName -m "tag message" – Create an annotated tag

git show tagName – Show tag information

git push origin tagName – Push a tag to remote repository

git push origin --tags – Push all tags to remote repository

git tag -d tagName – Delete a tag locally

git push --delete origin tagName – Delete a tag from the remote repository