Introduction to Version Control and Git for absolute beginners


1. Introduction to Version Control

What is Version Control?

Version control is a system that helps you manage changes to your files, especially code, over time. Imagine you're working on a programming project, and you want to keep track of the changes you make so you can go back to a previous version if something goes wrong. Version control systems (VCS) do just that! They record changes to a file or set of files, allowing you to revert to specific versions, compare different versions, and collaborate with others.

Benefits of Version Control

 

2. Introduction to Git

What is Git?

Git is a distributed version control system. This means that every developer working on a project has a complete copy of the project's history on their computer. Unlike centralized systems where all the history is stored on a single server, Git allows for more flexibility and reliability. You can work offline, and your changes can be shared with others when you're ready.

Basic Git Terminology

 

3. Setting Up Git

Installing Git

To start using Git, you need to install it on your computer. Here's a quick guide for different operating systems:

git --version

sudo apt-get install git

git --version

Configuring Git

Before you start using Git, you need to set up your identity. This is important because every Git commit uses this information.

  1. Open your terminal (or Git Bash on Windows).
  2. Set your username with the following command:

git config --global user.name "Your Name"

  1. Set your email address with this command:

git config --global user.email "your.email@example.com"

Creating a Repository

To start a new project with Git:

  1. Navigate to your project directory in the terminal:

cd path/to/your/project

  1. Initialize a new Git repository:

git init

This creates a hidden .git folder in your project directory. Now, your project is under version control!


4. Basic Git Commands

Now that your project is set up, let's go over some basic Git commands.

1. git init

2. git add

To add all changes:

git add .

3. git commit

git commit -m "Your commit message"

4. git status

git status

5. git log

git log

6. git branch

git branch

git branch branch-name

7. git merge

git merge branch-name

8. git checkout

git checkout branch-name

With these basics, you're ready to start using Git to manage your projects and collaborate with others! Remember, practice makes perfect, so try these commands out on a small project to get comfortable with version control.