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 checkoutandgit reset) - Branching (
git branchandgit checkout) - Merge Branches (
git merge) - Remove Files (
git rm) - Delete or Rename Branch (
git branch) - Push and Pull (
git pushandgit 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 secSet your GPG key for signing commits.
Starts a new Git repository by creating a .git directory (hidden on Unix-based systems).
git initInitialize Git repo in current directory.
mkdir MyProject
cd MyProject
git initCreate a new directory and initialize a Git repo inside.
Stages files to be committed.
git add fileNameAdd a single file to the staging area.
git add -AAdd all files (tracked and untracked) to staging.
git add .Add all files in the current directory and subdirectories.
Shows the commit history.
git logShow full commit history with details.
git log --oneline -5Show 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 statusRemove untracked files from working directory.
git clean -fRemove untracked files (use -f to force).
Remove files from the staging area.
git reset fileNameShow changes between working directory, staging area, and commits.
git diff HEADShow changes since last commit.
git diff --stagedShow staged changes.
git diff branchNameShow difference between current branch and another branch.
Restore files or move HEAD pointer.
git checkout -- fileNameRevert file to last committed state.
git reset commitHashMove HEAD to a specific commit, unstaging changes.
git reset --hard commitHashMove HEAD and discard all changes.
Manage branches.
git branchList branches.
git branch branchNameCreate a new branch.
git checkout -b branchNameCreate and switch to new branch.
git checkout branchNameSwitch to an existing branch.
Merge changes from another branch into the current branch.
git merge branchNameRemove files from Git and filesystem.
git rm fileNameRestore file after accidental remove:
git checkout HEAD fileNamegit branch -d branchNameDelete branch.
git branch -M branchNameRename branch (commonly used to rename default branch to main).
Synchronize with remote repositories.
git push origin masterPush master branch to remote origin.
git pull origin masterFetch and merge master branch from remote.
Manage remote repositories.
git remoteList remotes.
git remote add origin urlAdd a new remote named origin.
git remote remove remoteNameRemove a remote.
git remote rename oldName newNameRename a remote.
git show commitIDShow details of a specific commit.
git tagList tags.
git tag -a tagName -m "description"Create an annotated tag.
git show tagNameShow tag details.
Show line-by-line author info.
git blame fileName -L startLine,endLineShow authorship info for a range of lines.
Find the commit that introduced a bug.
git bisect start
git bisect bad
git bisect good commitHashBisect between good and bad commits.
git bisect resetStop bisect and return to original state.
Save uncommitted changes temporarily.
git stashgit stash listgit stash pop stash@{0}Copy remote repository locally.
git clone repositoryAddressApply a commit from another branch to the current one.
git cherry-pick commitHashThis 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