Most Useful Git Commands
1. Basic Setup
- git init
Initializes a new Git repository in the current directory.
- git clone <repository-url>
Clones an existing repository to your local machine.
- git config --global user.name "Your Name"
Sets your Git username globally.
- git config --global user.email "[email protected]"
Sets your Git email globally.
2. Working with Changes
- git status
Shows the status of your working directory and staged changes.
- git add <file>
Stages a specific file for commit. Use git add . to stage all files.
- git commit -m "Commit message"
Commits staged changes with a message.
- git diff
Shows the changes in your working directory compared to the last commit.
- git diff --staged
Shows the changes between the staging area and the last commit.
3. Working with Branches
- git branch
Lists all branches in the repository.
- git branch <branch-name>
Creates a new branch.
- git checkout <branch-name>
Switches to a specific branch.
- git switch <branch-name>
Alternative to git checkout for switching branches.