Git • GitHub • Developer Reference

Git & GitHub Quick Reference

A professional single-page guide for everyday Git usage — from initial setup and authentication to branches, syncing, stashing, diffs, recovery, and best practices.

Initial Setup

Configure your Git identity and inspect the settings Git uses on your machine.

Show current Git configuration

git config --list --show-origin

Displays all Git configuration values and the source file where each one is defined.

Edit global Git configuration

git config --global --edit

Opens your global Git config file. On Windows it is commonly located at C:\Users\shuva\.gitconfig.

Set your Git username

git config --global user.name "Shuvabrata Dey"

Defines the author name that will be attached to your commits.

Set your Git email

git config --global user.email "shuvabratadey@gmail.com"

Defines the author email used in your commit history.

Trust all repositories

git config --global --add safe.directory '*'

Marks all directories as safe for Git operations. Useful in some multi-user or permission-restricted environments.

Cache credentials

git config --global credential.helper cache

Temporarily remembers your credentials so you do not need to re-enter them every time.

Important

Do not store your GitHub password using custom Git config keys. Use a Personal Access Token or Git Credential Manager instead.

Create or Connect a Repository

Start a repository locally, connect it to GitHub, or clone an existing project.

Initialize a new repository

git init

Creates a new local Git repository in the current folder.

Add a remote origin

git remote add origin <repository-link>

Links your local repository to a remote GitHub repository.

View remote URLs

git remote -v

Shows the remote repository URLs used for fetch and push.

Clone an existing repository

git clone https://github.com/shuvabratadey/FPGA-CPU-Design.git

Downloads a copy of the remote repository to your local machine.

Authentication with GitHub Token

GitHub no longer accepts standard account passwords for Git over HTTPS. Use a Personal Access Token instead.

Create a GitHub token

https://github.com/settings/tokens

Generate a Personal Access Token from your GitHub account settings.

Push after token creation

git push origin master

When prompted, enter your GitHub username and paste the token where Git asks for the password.

Best Practice

On Windows, using git config --global credential.helper manager-core is usually better than plain credential caching.

Basic Daily Workflow

These are the commands you will use most often while working on a project.

Check repository status

git status

Shows changed, staged, and untracked files.

Stage all changes

git add .

Adds all current changes to the staging area.

Stage one file

git add <file_name>

Stages only the selected file.

Create a commit

git commit -m "Your commit message"

Saves the staged changes in a commit with a descriptive message.

Push to remote

git push origin master

Uploads your local commits to the remote branch.

Set upstream while pushing

git push --set-upstream origin master

Pushes the branch and links it to the remote tracking branch.

Note

Many repositories use main instead of master. Use the correct default branch for your project.

Branching

Create, switch, list, and delete branches as part of a clean development workflow.

Create a branch

git branch <branch_name>

Creates a new branch without switching to it.

Switch to a branch

git checkout <branch_name>

Moves your working directory to the selected branch.

Create and switch

git checkout -b <branch_name>

Creates a new branch and switches to it immediately.

Modern switch command

git switch <branch_name>

A newer and clearer alternative to git checkout for changing branches.

Push a branch

git push origin <branch_name>

Uploads the selected branch to GitHub.

Delete a local branch

git branch -d <branch_name>

Deletes a merged local branch.

Force delete a local branch

git branch -D <branch_name>

Deletes a branch even if it has not been merged.

Delete a remote branch

git push origin --delete <branch_name>

Removes the branch from the remote repository.

Syncing with Remote

Keep your local repository updated and integrate changes from GitHub correctly.

Pull latest changes

git pull origin master

Fetches and merges the latest changes from the remote branch.

Set upstream while pulling

git pull --set-upstream origin master

Associates your current branch with the remote tracking branch while pulling.

Fetch without merging

git fetch

Downloads changes from the remote repository without merging them.

Fetch all remotes

git fetch --all

Retrieves updates from all configured remotes.

Merge fetched branch

git merge origin/master

Merges the fetched remote branch into your current branch.

Pull with rebase

git pull --rebase origin master

Reapplies your local commits on top of the updated remote history.

Stash Commands

Temporarily save unfinished work so you can switch branches or pull updates safely.

Save current work

git stash

Stores your uncommitted changes temporarily.

Restore latest stash

git stash pop

Reapplies the most recent stash and removes it from the stash list.

Apply stash without deleting

git stash apply

Reapplies a stash but keeps it available for reuse.

List all stashes

git stash list

Shows every saved stash entry.

Delete one stash

git stash drop stash@{0}

Deletes the selected stash entry.

Clear all stashes

git stash clear

Removes all saved stash entries permanently.

Logs and History

Inspect commit history to understand the timeline of changes in your repository.

Show commit history

git log

Displays detailed commit history.

Compact one-line history

git log --oneline

Shows a condensed list of commits.

Graph view

git log --all --decorate --graph --oneline

Displays a branch graph with labels for commits, branches, and tags.

Last commit only

git log -1

Shows the details of the most recent commit.

Show line authorship

git blame <file_name>

Shows who last changed each line in a file.

Difference Checking

Compare working files, staged changes, branches, or specific commits.

Show unstaged changes

git diff

Displays differences that are not yet staged.

Show changes in one file

git diff <file_path/file_name>

Displays changes for a particular file only.

Show staged changes

git diff --staged

Shows changes already added to the staging area.

Compare two commits

git diff <commit1> <commit2>

Displays the difference between any two commits.

Compare branches

git diff master..feature-branch

Shows what differs between two branches.

Checkout and Restore

Move between commits and branches, or discard unwanted local changes.

Checkout a specific commit

git checkout <commit_id>

Moves your working directory to a selected commit.

Go back to the previous branch

git checkout -

Returns to the last checked-out branch.

Restore a file

git restore <file_name>

Discards changes in a file and restores the last committed version.

Unstage a file

git restore --staged <file_name>

Removes a file from the staging area while keeping the file changes.

Reset and Revert

Undo commits or move your branch pointer depending on whether you want to rewrite history or preserve it.

Soft reset last commit

git reset --soft HEAD~1

Removes the last commit but keeps the changes staged.

Mixed reset last commit

git reset HEAD~1

Removes the last commit and unstages the changes.

Hard reset last commit

git reset --hard HEAD~1

Deletes the last commit and permanently removes the changes from your working directory.

Reset to a specific commit

git reset --hard <commit_id>

Moves the current branch to a particular commit.

Safely undo a commit

git revert <commit_id>

Creates a new commit that reverses the selected commit without rewriting project history.

Warning

Use git reset --hard carefully. It permanently removes uncommitted changes from your working directory.

Tagging

Use tags to mark important versions such as releases or milestones.

Create a lightweight tag

git tag v1.0

Creates a simple tag for a release or checkpoint.

Create an annotated tag

git tag -a v1.0 -m "Version 1.0 release"

Creates a tag with extra metadata such as message, author, and date.

Push all tags

git push origin --tags

Uploads all local tags to the remote repository.

List tags

git tag

Displays every tag available in the repository.

Useful Inspection Commands

Quick commands for checking branch names, tracked files, and commit identifiers.

Show current branch

git branch --show-current

Displays the active branch name.

Show current commit hash

git rev-parse HEAD

Prints the full commit ID of the current HEAD.

List tracked files

git ls-files

Shows all files currently tracked by Git.

Remove untracked files

git clean -f

Deletes untracked files from the working directory.

Remove untracked files and folders

git clean -fd

Deletes untracked files and directories.

Open GitHub Project in VS Code Online

You can view a GitHub repository in a browser-based VS Code style interface by replacing part of the URL.

Original repository URL

https://github.com/shuvabratadey/ESP-IDF-Free-RTOS

This is the standard GitHub repository link.

GitHub1s URL

https://github1s.com/shuvabratadey/ESP-IDF-Free-RTOS

Add 1s after github to open the repository in an online VS Code-like viewer.

Detached HEAD Fix

If you checked out a commit directly and want to move your branch back to that commit, these steps help recover it.

1

Check the latest commit

git log -1
2

Switch back to your branch

git checkout master
3

Move the branch to the detached commit

git reset --hard <commit-id>

Recommended Beginner Workflow

A clean starting workflow for creating a project locally and pushing it to GitHub for the first time.

1

Initialize the repository

git init
2

Connect remote origin

git remote add origin <repository-link>
3

Stage all files

git add .
4

Create the first commit

git commit -m "Initial commit"
5

Rename default branch

git branch -M main
6

Push and connect upstream

git push --set-upstream origin main
Professional Tip

Use clear commit messages, prefer main for new repositories, and avoid force operations unless you fully understand the impact.