Essential Git Commands
Here’s a curated list of essential Git commands to help you manage repositories, branches, commits, and handle advanced workflows. Mastering these commands will provide a solid foundation in Git.
1. Basic Setup & Initialization
git init
: Initializes a new Git repository.git clone <repository-url>
: Clones an existing repository.git config
: Configures user details (e.g., username, email).
2. Tracking and Staging Changes
git add <file>
: Stages specific files for commit.git add .
: Stages all changes in the current directory.git status
: Displays the current state of the working directory.
3. Committing Changes
git commit -m "message"
: Commits staged changes.git commit --amend -m "new message"
: Modifies the last commit.
4. Branching and Merging
git branch
: Lists or creates branches.git checkout <branch>
: Switches to a different branch.git merge <branch>
: Merges a branch into the current branch.
5. Working with Remote Repositories
git remote add origin <repository-url>
: Links local repo to remote.git push -u origin <branch>
: Pushes branch to remote.git pull
: Fetches and merges changes from remote.
6. Undoing Changes
git reset <file>
: Unstages a staged file.git reset --hard <commit>
: Resets working directory to a commit.git revert <commit>
: Creates a commit that undoes a specified commit.
7. Viewing Logs and History
git log
: Shows commit history.git log --oneline --graph
: Condensed, graphical history.git diff
: Shows differences in working directory.
8. Tagging
git tag <tag-name>
: Creates a tag for a release.git push origin <tag>
: Pushes a tag to remote.
9. Stashing Changes
git stash
: Saves and clears changes temporarily.git stash pop
: Restores the most recent stash.
Mastering these Git commands will help you manage and collaborate on projects with confidence!
Thanks for your feedback