Welcome to LearnMoreGit, a comprehensive guide to Git commands with clear explanations and practical examples. This README covers essential Git commands for beginners and intermediate users, focusing on real-world usage and understanding.
- Git Configuration (
git config
) - Initialize a Git Repository (
git init
) - Adding Files to Git (
git add
) - Viewing Commit History (
git log
) - Commit Changes (
git commit
) - Check Repository Status (
git status
) - Clean Untracked Files (
git clean
) - Unstage a File (
git reset
) - Show Differences (
git diff
) - Revert Changes (
git checkout
andgit reset
) - Branching (
git branch
andgit checkout
) - Merge Branches (
git merge
) - Remove Files (
git rm
) - Delete or Rename Branch (
git branch
) - Push and Pull (
git push
andgit pull
) - Manage Remotes (
git remote
) - Show Commit or Tag Details (
git show
) - View File History (
git blame
) - Debug with Bisect (
git bisect
) - Stashing Changes (
git stash
) - Clone Repository (
git clone
) - Cherry-pick Commits (
git cherry-pick
) - Summary
git config
is used to configure Git settings such as user information, proxy settings, and signing keys. These settings help Git identify who is making commits and control other behaviors.
git config --global user.name "UserName"
Set your Git username globally (used in commits).
git config --global user.email "Email"
Set your email globally.
git config --global user.signingkey sec
Set your GPG key for signing commits.
Starts a new Git repository by creating a .git
directory (hidden on Unix-based systems).
git init
Initialize Git repo in current directory.
mkdir MyProject
cd MyProject
git init
Create a new directory and initialize a Git repo inside.
Stages files to be committed.
git add fileName
Add a single file to the staging area.
git add -A
Add all files (tracked and untracked) to staging.
git add .
Add all files in the current directory and subdirectories.
Shows the commit history.
git log
Show full commit history with details.
git log --oneline -5
Show the last 5 commits in a simplified one-line format.
Save staged changes with a message.
git commit -m "Title"
Commit with a short message.
git commit -m "Title" -m "Description"
Commit with a title and longer description.
git commit -am "Title"
Commit tracked files with changes without git add
.
Shows the current state of the working directory and staging area.
git status
Remove untracked files from working directory.
git clean -f
Remove untracked files (use -f
to force).
Remove files from the staging area.
git reset fileName
Show changes between working directory, staging area, and commits.
git diff HEAD
Show changes since last commit.
git diff --staged
Show staged changes.
git diff branchName
Show difference between current branch and another branch.
Restore files or move HEAD pointer.
git checkout -- fileName
Revert file to last committed state.
git reset commitHash
Move HEAD to a specific commit, unstaging changes.
git reset --hard commitHash
Move HEAD and discard all changes.
Manage branches.
git branch
List branches.
git branch branchName
Create a new branch.
git checkout -b branchName
Create and switch to new branch.
git checkout branchName
Switch to an existing branch.
Merge changes from another branch into the current branch.
git merge branchName
Remove files from Git and filesystem.
git rm fileName
Restore file after accidental remove:
git checkout HEAD fileName
git branch -d branchName
Delete branch.
git branch -M branchName
Rename branch (commonly used to rename default branch to main
).
Synchronize with remote repositories.
git push origin master
Push master branch to remote origin
.
git pull origin master
Fetch and merge master branch from remote.
Manage remote repositories.
git remote
List remotes.
git remote add origin url
Add a new remote named origin.
git remote remove remoteName
Remove a remote.
git remote rename oldName newName
Rename a remote.
git show commitID
Show details of a specific commit.
git tag
List tags.
git tag -a tagName -m "description"
Create an annotated tag.
git show tagName
Show tag details.
Show line-by-line author info.
git blame fileName -L startLine,endLine
Show authorship info for a range of lines.
Find the commit that introduced a bug.
git bisect start
git bisect bad
git bisect good commitHash
Bisect between good and bad commits.
git bisect reset
Stop bisect and return to original state.
Save uncommitted changes temporarily.
git stash
git stash list
git stash pop stash@{0}
Copy remote repository locally.
git clone repositoryAddress
Apply a commit from another branch to the current one.
git cherry-pick commitHash
This README provides fundamental Git commands and practical examples to help you get started and manage your projects efficiently. For detailed help, use git help <command>
or visit the official Git documentation.
Happy Git learning! 🚀
Created by Max Base