Installing Git
To start using Git, you'll need to install it on your system. Here are the steps for various operating systems:
Windows
- Download the Git installer from the official Git website.
- Run the installer and follow the on-screen instructions.
- During installation, select your preferred editor and adjust the PATH environment options if necessary.
macOS
- Open Terminal and install Git using
brew
(requires Homebrew): brew install git
- Verify installation by running
git --version
.
Linux
- Use your package manager to install Git. For example:
- Debian/Ubuntu:
sudo apt install git
- Fedora:
sudo dnf install git
- Arch:
sudo pacman -S git
- Verify installation by running
git --version
.
Getting Started with Git
Once Git is installed, follow these steps to get started:
1. Configuring Git
Set your user name and email address:
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
2. Creating Your First Repository
- Create a new directory:
mkdir my-project
- Navigate to the directory:
cd my-project
- Initialize a Git repository:
git init
3. Basic Commands
git status
: Check the status of your repository.git add <file>
: Stage changes for commit.git commit -m "Your commit message"
: Commit changes.git log
: View commit history.
Understanding Git Concepts
Here are some key concepts you need to understand:
1. Repositories
A repository is a directory that Git tracks. It contains all your project files and the history of changes.
2. Commits
A commit is a snapshot of your project at a specific point in time. Each commit has a unique ID and message.
3. Branches
Branches allow you to work on different versions of your project simultaneously. The default branch is usually main
.
4. History
The history is a record of all commits in your repository. Use git log
to view it.
0 Comments