Git Basics

Installing Git

To start using Git, you'll need to install it on your system. Here are the steps for various operating systems:

Windows

  1. Download the Git installer from the official Git website.
  2. Run the installer and follow the on-screen instructions.
  3. During installation, select your preferred editor and adjust the PATH environment options if necessary.

macOS

  1. Open Terminal and install Git using brew (requires Homebrew):
  2. brew install git
  3. Verify installation by running git --version.

Linux

  1. Use your package manager to install Git. For example:
  2. Debian/Ubuntu: sudo apt install git
  3. Fedora: sudo dnf install git
  4. Arch: sudo pacman -S git
  5. 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

  1. Create a new directory: mkdir my-project
  2. Navigate to the directory: cd my-project
  3. 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.

Post a Comment

0 Comments