Skip to main content
Advertisement

Git & GitHub: Starting Version Control

1. What is Git?

Git is a distributed version control system (VCS) designed to track changes in source code. It enables multiple developers to collaborate and manage a project's history effectively.


2. Core Workflow

  1. Working Directory: The files you are currently editing.
  2. Staging Area: A landing zone where changes are prepared before being recorded to the repository (git add).
  3. Local Repository (.git): The database on your own computer where changes are permanently recorded (git commit).
  4. Remote Repository: The repository hosted on a server (e.g., GitHub, GitLab) for sharing and collaboration (git push).

3. Essential Commands

# Initialize a new repository
git init

# Stage changes
git add .

# Save changes with a message
git commit -m "First commit"

# Connect to a remote repository and push
git remote add origin https://github.com/user/repo.git
git push -u origin main

4. Using Branches

Branches allow you to create independent workspaces so you can develop features safely without affecting the main codebase.

# Create and switch to a new branch
git checkout -b feature/new-logic

# Merge a branch (executed from the main branch)
git merge feature/new-logic
Advertisement