Git Commands

Try searching for: "list", "docker run", "git branch", "remove directory"
Search Results

Git Commands

Basics

git init

Initialize a new Git repository.

Example: git init my_project
init repository
git clone <repo_url>

Clone a remote repository.

Example: git clone https://github.com/user/repo.git
clone repository
git status

Show the current status of the working directory.

Example: git status
status workspace
git add <file>

Add changes to the staging area.

Example: git add README.md
add stage
git commit -m "message"

Commit staged changes with a message.

Example: git commit -m "Initial commit"
commit save

Staging

git restore --staged <file>

Remove file from staging area.

Example: git restore --staged README.md
restore unstage staging
git restore <file>

Discard changes in working directory.

Example: git restore config.js
restore discard changes
git reset <file>

Remove file from staging area (legacy).

Example: git reset HEAD file.txt
reset unstage staging

Branching

git branch

List all branches.

Example: git branch --all
list branches
git checkout <branch_name>

Switch to a different branch.

Example: git checkout develop
switch branch
git checkout -b <branch_name>

Create and switch to a new branch.

Example: git checkout -b feature/new-feature
create switch branch
git merge <branch_name>

Merge a branch into the current branch.

Example: git merge feature/new-feature
merge branch
git branch -d <branch_name>

Delete a branch.

Example: git branch -d feature/old-feature
delete branch
git switch <branch>

Switch to a different branch (modern alternative to checkout).

Example: git switch develop
switch branch modern
git stash

Temporarily save uncommitted changes.

Example: git stash push -m "work in progress"
stash save temporary
git stash pop

Restore and remove most recent stashed changes.

Example: git stash pop
stash restore pop

Remote

git remote -v

Show remote repositories.

Example: git remote -v
list remote
git push origin <branch_name>

Push changes to a remote repository.

Example: git push origin main
push remote
git pull origin <branch_name>

Pull changes from a remote repository.

Example: git pull origin main
pull remote
git fetch

Fetch changes from remote without merging.

Example: git fetch origin
fetch remote
git branch -u origin/<branch>

Set upstream tracking for current branch.

Example: git branch -u origin/main
upstream tracking branch
git fetch --prune

Fetch changes and remove stale remote branches.

Example: git fetch --prune origin
fetch prune cleanup

Analysis

git show <commit>

Display details and changes of a specific commit.

Example: git show abc123
show commit details
git blame <file>

Show who last modified each line of a file.

Example: git blame src/main.js
blame author history
git tag

List all tags in the repository.

Example: git tag --sort=-version:refname
tag list version
git tag <name>

Create a new tag at current commit.

Example: git tag v1.0.0
tag create version

History

git log

Show commit history.

Example: git log --oneline
log history
git diff

Show changes between commits or working directory.

Example: git diff HEAD~1
diff changes
git reset <commit>

Reset to a specific commit.

Example: git reset --hard HEAD~1
reset commit
git revert <commit>

Revert a specific commit.

Example: git revert abc123
revert commit