Home > Web Development > Complete Git Guide: Installation, Usage, and Branches

Complete Git Guide: Installation, Usage, and Branches

Diego Cortés
Diego Cortés
January 20, 2025
Complete Git Guide: Installation, Usage, and Branches

Git is a fundamental tool for software development that allows programmers to maintain detailed control over their projects. In this guide, we will explore the necessary steps to install Git, how to use its main features, and branch management, which is essential for efficient collaborative work.

What is Git?

Git is a distributed version control system that enables developers to track changes in their code, collaborate on projects with others, and manage multiple versions of the same project. This tool is especially popular among software developers, but its versatility allows it to be used in any type of project that requires change tracking.

Installing Git

To start using Git, you first need to install it on your system. Instructions vary by operating system:

On Windows

  1. Download the Installer: Go to the official Git site and download the installer for Windows.
  2. Installation: Run the installer and follow the instructions. Accept the default values unless you have a reason to change the configuration.
  3. Verification: Once the installation is complete, open the command line and run the command git --version to check that it was installed correctly.

On macOS

  1. Using Homebrew: If you have Homebrew installed, you can use the following command: 
  2. brew install git
  3. Verification: Similar to Windows, run git --version in the terminal to ensure that the installation was successful.

On Linux

For Debian/Ubuntu-based distributions, use:

sudo apt-get install git

For Red Hat/Fedora-based distributions, use:

sudo dnf install git

Afterward, run git --version to confirm the installation.

Basic Usage of Git

Once Git is installed, you can start using it. Some basic commands include:

Initialize a Repository

To create a new repository, navigate to the desired folder in your terminal and run:

git init

Add Files

To prepare files to be tracked, use the command:

git add filename

If you want to add all the files in the directory, use git add ..

Commit Changes

Once you have added the files, you can commit the changes with:

git commit -m "Commit message"

It’s important to include a message that describes the changes made.

Branch Management

Branches in Git are essential for working on different features of a project without affecting the main version. To manage branches, use the following commands:

Create a New Branch

To create a new branch, run:

git branch branch_name

Switch Branches

To switch to an existing branch, use:

git checkout branch_name

Merge Branches

Once you have finished working on a branch and want to merge it with the main branch, make sure you are on the main branch and run:

git merge branch_name

Conclusion

Understanding Git is not only valuable for developers but is also applicable in many other fields where change tracking is required. With this guide, you will be able to start working with Git on a basic level and delve into its collaborative use through branches.

I invite you to read more news of this style on my blog, where you will find related content that will help you deepen your knowledge of useful tools for development and collaboration.

Diego Cortés
Diego Cortés
Full Stack Developer, SEO Specialist with Expertise in Laravel & Vue.js and 3D Generalist

Categories

Page loaded in 23.26 ms