Git Command Basics
What is Git?
Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It allows multiple developers to work together, tracking changes and managing source code.
Basic Git Commands
Initializing a Repository
To start using Git, you first need to initialize a repository:
## Create a new directory
mkdir my-project
cd my-project
## Initialize a new Git repository
git init
Configuring Git
Set up your Git configuration with your name and email:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Core Git Workflow
Staging and Committing Changes
## Check repository status
git status
## Add files to staging area
git add filename.txt
git add . ## Add all files
## Commit changes
git commit -m "Descriptive commit message"
Branching and Merging
gitGraph
commit
branch feature-branch
checkout feature-branch
commit
checkout main
merge feature-branch
Basic Git Commands Overview
Command |
Purpose |
git clone |
Copy a remote repository |
git pull |
Download and merge changes |
git push |
Upload local changes |
git branch |
List, create, or delete branches |
git checkout |
Switch between branches |
Best Practices
- Commit often
- Write clear, descriptive commit messages
- Use branches for new features
- Pull changes before pushing
At LabEx, we recommend mastering these fundamental Git commands to improve your version control skills.