This repository contains essential Git commands with explanations to help developers efficiently manage their projects using Git.
git --version
Checks the installed Git version.
git init
Creates a new Git repository in the current directory.
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
Sets your global Git username and email.
git config --list
Lists all configured Git settings.
git status
Shows the current state of the repository, including untracked and modified files.
git add <file1> <file2>
Adds specific files to the staging area.
git add .
Adds all changes to the staging area.
git commit -m "Your commit message"
Creates a new commit with the staged changes.
git log
Displays a list of previous commits with details.
git log --oneline
Shows commit history in a compact format.
git branch
Shows all local branches.
git branch <branch-name>
Creates a new branch without switching to it.
git switch <branch-name>
Switches to an existing branch.
git switch -c <branch-name>
Creates a new branch and switches to it.
git merge <branch-name>
Merges the specified branch into the current branch.
git rebase <branch-name>
Reapplies commits from the current branch onto the specified branch.
git cherry-pick <commit-id>
Applies a specific commit from another branch.
git branch -m <old-branch-name> <new-branch-name>
Renames an existing branch.
git branch -d <branch-name>
Deletes a branch if it is merged.
git branch -D <branch-name>
Force deletes a branch, even if it is not merged.
git remote add origin <repository-url>
Links the local repository to a GitHub repository.
git push -u origin main
Uploads the local commits to the GitHub repository.
git pull origin main
Fetches and merges the latest changes from the remote repository.
This guide covers fundamental Git commands for efficient version control. Keep practicing and exploring Git to improve your workflow!