git init
Initializes a new Git repository.
$ git init
Initialized empty Git repository in /path/to/repository/
git clone
Clones a remote repository to your local machine.
$ git clone https://github.com/username/repository.git
Cloning into
git add
Stages changes for commit.
$ git add file.txt
git status
Shows the status of the working directory and staged changes.
$ git status
git commit
Commits staged changes.
$ git commit -m "Added new feature"
git log
Displays commit history.
$ git log
git diff
Shows differences between working directory and staged changes.
$ git diff
git branch
Lists branches.
$ git branch
git checkout
Switches branches or restores files.
$ git checkout branch_name
git merge
Merges changes from one branch into another.
$ git merge feature_branch
git pull
Fetches and integrates changes from a remote repository.
$ git pull origin master
git push
Pushes changes to a remote repository.
$ git push origin master
git remote
Manages remote repositories.
$ git
git fetch
Downloads objects and refs from a remote repository.
$ git fetch origin
git stash
Temporarily stores changes to work on something else.
$ git stash
git tag
Creates and manages tags for specific commits.
$ git tag v1.0.0
git reset
Unstages changes or moves the HEAD to a specific commit.
$ git reset HEAD file.txt
git rebase
Reapplies commits on top of another base.
$ git rebase master
git config
Sets configuration options.
$ git config --global user.name "Your Name"
$ git config --global user.email "your.email@example.com"
git log --oneline
Displays compact commit history.
$ git log --oneline
git show
Shows information about a commit.
$ git show commit_hash
git cherry-pick
Applies a commit from one branch to another.
$ git cherry-pick commit_hash
git rm
Removes files from the working directory and stages the removal.
$ git rm file.txt
git revert
Creates a new commit that undoes changes from a previous commit.
$ git revert commit_hash
git reflog
Displays the history of HEAD positions.
$ git reflog
git clean
Removes untracked files and directories from the working directory.
$ git clean -n # Dry-run
$ git clean -f # Force
git tag -a
Creates an annotated tag with a message.
$ git tag -a v1.0.0 -m "Version 1.0.0"
git log --graph
Displays commit history as a graph.
$ git log --graph --oneline
git config --list
Lists all Git configuration settings.
$ git config --list
git log --since
/ git log --until
Displays commit history within a time range.
$ git log --since="2 weeks ago"
$ git log --until="2023-07-01"
git cherry
Shows commits that have not been merged.
$ git cherry master feature_branch
git revert --no-commit
Reverts changes interactively without committing.
$ git revert --no-commit commit_range
git log --author
Filters commit history by author.
$ git log --author="John Doe"
git log --stat
Displays file statistics with commit history.
$ git log --stat
git blame
Shows who last modified each line in a file.
$ git blame file.txt
git tag -d
Deletes a tag.
$ git tag -d v1.0.0
git log -p
Displays commit history with patch diffs.
$ git log -p
git rev-parse
Converts a revision string into a SHA-1 hash.
$ git rev-parse HEAD
git remote -v
Lists remote repositories and their URLs.
$ git
git log --decorate
Displays references (branches, tags) in commit history.
$ git log --decorate
git bisect
Performs a binary search to find a faulty commit.
$ git bisect start
$ git bisect good <commit>
$ git bisect bad <commit>
$ git bisect reset
git log --grep
Searches commit messages for a specific keyword.
$ git log --grep="bug fix"
git log --name-only
Displays only file names in commit history.
$ git log --name-only
git rebase -i
Interactively rewrites commit history.
$ git rebase -i HEAD~3
git log --before
/ git log --after
Displays commit history before/after a specific date.
$ git log --before="2023-01-01"
$ git log --after="2022-01-01"
git checkout -b
Creates a new branch and switches to it.
$ git checkout -b new_feature
git log --cherry-pick
Shows commits that have been cherry-picked.
$ git log --cherry-pick master..feature_branch
git log -S
Searches for changes that added or removed a specific string.
$ git log -S "function_name"
git reflog expire
Expires old reflog entries.
$ git reflog expire --expire=30.days refs/heads/master
git commit --amend
Modifies the most recent commit.
$ git commit --amend