0% found this document useful (0 votes)
6 views4 pages

Git Commands CheatSheet

This document provides a comprehensive overview of essential Git commands and their explanations, covering basic configuration, repository initialization, staging and committing, branching, remote repositories, viewing history, undoing changes, stashing, tagging, and other utilities. Each command is accompanied by a brief description of its function. This serves as a quick reference guide for users to effectively manage their Git repositories.

Uploaded by

prajaktamusale26
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)
6 views4 pages

Git Commands CheatSheet

This document provides a comprehensive overview of essential Git commands and their explanations, covering basic configuration, repository initialization, staging and committing, branching, remote repositories, viewing history, undoing changes, stashing, tagging, and other utilities. Each command is accompanied by a brief description of its function. This serves as a quick reference guide for users to effectively manage their Git repositories.

Uploaded by

prajaktamusale26
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
You are on page 1/ 4

Git Commands with Explanations

Basic Configuration

git config --global user.name "Your Name"

-> Set your name for Git commits.

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

-> Set your email for Git commits.

git config --global core.editor "editor"

-> Set default editor (e.g., VSCode, Vim).

git config --list

-> View all current Git configurations.

Repository Initialization

git init

-> Initialize a new Git repository in the current directory.

git clone <repo_url>

-> Clone a repository from a remote URL to your local machine.

Staging and Committing

git status

-> Show the status of changes (staged, unstaged, untracked).

git add <file>

-> Stage a specific file for commit.

git add .

-> Stage all changes in the current directory.

git commit -m "message"

-> Commit staged changes with a message.

git commit -a -m "message"

-> Stage and commit all tracked files in one step.

Branching
Git Commands with Explanations

git branch

-> List all local branches.

git branch <branch-name>

-> Create a new branch.

git checkout <branch-name>

-> Switch to a specific branch.

git checkout -b <branch-name>

-> Create and switch to a new branch.

git merge <branch-name>

-> Merge the specified branch into the current branch.

git branch -d <branch-name>

-> Delete a local branch.

Remote Repositories

git remote -v

-> View remote repository URLs.

git remote add origin <url>

-> Add a remote repository.

git push -u origin <branch>

-> Push branch to remote and set upstream.

git push

-> Push committed changes to the remote.

git pull

-> Fetch and merge changes from the remote.

git fetch

-> Fetch changes from remote but don't merge.

Viewing History

git log

-> Show commit history.


Git Commands with Explanations

git log --oneline

-> Condensed, one-line log view.

git log --graph --all

-> Visual graph of all branches and history.

Undoing Changes

git restore <file>

-> Discard changes in the working directory.

git restore --staged <file>

-> Unstage a file (move from staged to unstaged).

git reset HEAD <file>

-> Unstage changes.

git reset --soft HEAD~1

-> Undo last commit but keep changes staged.

git reset --mixed HEAD~1

-> Undo last commit and unstage changes.

git reset --hard HEAD~1

-> Remove last commit and discard all changes.

Stashing

git stash

-> Save current changes temporarily.

git stash list

-> View list of stashed changes.

git stash apply

-> Reapply stashed changes.

git stash drop

-> Delete the latest stash.

Tagging
Git Commands with Explanations

git tag

-> List all tags.

git tag <tagname>

-> Create a lightweight tag.

git tag -a <tagname> -m "message"

-> Create an annotated tag.

git push origin <tagname>

-> Push a tag to remote.

git push --tags

-> Push all tags to remote.

Others & Utilities

git diff

-> Show differences between files.

git diff --staged

-> Show differences in staged files.

git show <commit>

-> Show details of a specific commit.

git blame <file>

-> Show who made each line change in a file.

git clean -f

-> Remove untracked files from working directory.

You might also like