Getting Started
Configure Git
git config --global user.name "Your Name"Set your username for Git commits.
git config --global user.email "you@example.com"Set your email for Git commits.
git config --global core.editor "editor"Set your default text editor (e.g., nano, vim).
git config --global core.autocrlf inputHandle line endings automatically.
Initialize Repository
git initInitialize a new Git repository.
Clone Repository
git clone URLClone an existing repository from a remote URL.
Basic Commands
Check Status
git statusShow the working directory and staging area status.
Add Files
git add fileStage a specific file for commit.
git add .Stage all changes in the directory.
Commit Changes
git commit -m "Commit message"Commit staged changes with a message.
git commit --amendAmend the last commit with new changes.
Remove Files
git rm fileRemove a file from the working directory and staging area.
git rm --cached fileRemove a file from the staging area only.
Branching
List Branches
git branchList all local branches.
Create Branch
git branch branch-nameCreate a new branch.
Switch Branch
git checkout branch-nameSwitch to an existing branch.
git checkout -b branch-nameCreate and switch to a new branch.
Delete Branch
git branch -d branch-nameDelete a branch that has been merged.
git branch -D branch-nameForce delete a branch.
Merging
Merge Branch
git merge branch-nameMerge a branch into the current branch.
Abort Merge
git merge --abortAbort a merge in progress.
Rebase
Rebase Branch
git rebase branch-nameRebase the current branch onto another branch.
Abort Rebase
git rebase --abortAbort a rebase in progress.
Continue Rebase
git rebase --continueContinue a rebase after resolving conflicts.
Stashing
Stash Changes
git stashStash uncommitted changes.
List Stashes
git stash listList all stashes.
Apply Stash
git stash applyApply the latest stash.
git stash apply stash@{n}Apply a specific stash.
Drop Stash
git stash dropRemove the latest stash.
git stash drop stash@{n}Remove a specific stash.
Remote Repositories
Add Remote
git remote add name URLAdd a new remote repository.
List Remotes
git remote -vList all configured remote repositories.
Fetch Changes
git fetch remoteFetch changes from a remote repository.
Pull Changes
git pull remote branchFetch and merge changes from a remote branch.
Push Changes
git push remote branchPush changes to a remote branch.
Delete Remote Branch
git push remote --delete branch-nameDelete a branch on the remote repository.
Viewing History
View Log
git logView commit history.
git log --onelineSimplified commit history.
Show Commit
git show commit-hashShow details of a specific commit.
View Difference
git diffShow unstaged changes.
git diff --stagedShow staged changes.
Tags
List Tags
git tagList all tags.
Create Tag
git tag tag-nameCreate a lightweight tag.
git tag -a tag-name -m "Message"Create an annotated tag with a message.
Delete Tag
git tag -d tag-nameDelete a local tag.
git push origin --delete tag tag-nameDelete a remote tag.
Undo Changes
Unstage Changes
git reset fileUnstage a file while keeping changes.
Revert Changes
git checkout -- fileDiscard changes in the working directory.
git revert commit-hashCreate a new commit to undo changes from a specific commit.
Reset to Commit
git reset --soft commit-hashReset to a commit, keeping changes staged.
git reset --hard commit-hashReset to a commit, discarding all changes.
Advanced Commands
Cherry-pick
git cherry-pick commit-hashApply changes from a specific commit.
Bisect
git bisect startStart a binary search to find a buggy commit.
git bisect good commit-hash
git bisect bad commit-hashMark commits as good or bad.
Submodules
git submodule add URLAdd a submodule.
git submodule update --initInitialize and update submodules.
References
For more in-depth information, visit the official Git documentation.
Discussion 0
Please sign in to join the discussion.
No comments yet. Start the discussion!