Chapter 39: Code versioning with Git

Code versioning is an essential part of modern software development, especially when working in teams. It allows developers to track changes made to a project over time, facilitating collaboration and conflict resolution. Git is one of the most popular and widely used code versioning tools, and is an essential skill for any front-end developer.

Introduction to Git

Git is a distributed version control system, which means that each developer has a complete copy of the code history on their local computer. This makes Git extremely fast and flexible, as operations are not dependent on a network connection. Git is also very powerful, with support for branching and merging code, which allows developers to work on different features or bug fixes simultaneously.

Installing Git

Before you can start using Git, you need to install it on your computer. The installation process varies depending on the operating system you are using. For most Unix systems, including Linux and macOS, Git can be installed through the native package manager. On Windows, you can download and install Git from the official website.

Configuring Git

After installing Git, there are some settings you need to adjust. First, you must define your name and email address, as this information will be used in all your confirmations. You can do this with the following commands:


git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

Git basics

Git has three main areas: the working directory, the index, and the Git repository. The working directory is where you make your code changes. The index is a staging area where you can add your changes before committing them to the Git repository, which is where Git stores the version history of your code.

Basic Git commands

Here are some of the basic Git commands you'll use regularly:

  • git init: This command creates a new Git repository in your current directory.
  • git add: This command adds files to the index. For example, "git add ." will add all modified files in the current directory to the index.
  • git commit: This command commits index changes to the Git repository. For example, "git commit -m 'commit message'" will commit with the given message.
  • git status: This command shows the status of your working directory and index.
  • git log: This command shows the commit history of the Git repository.

Git Branching and Merging

Git allows you to branch your code so you can work on different features or bug fixes simultaneously. When you're done, you can merge your branches back into the main branch. Here are some useful commands for branching and merging:

  • git branch: This command lists all the branches in your Git repository. If you add a branch name, for example "git branch feature1", it will create a new branch with that name.
  • git checkout: This command switches to a different branch. For example, "git checkout feature1" will switch to the "feature1" branch.
  • git merge: This command merges one branch into another. For example, if you are on the main branch and you run "git merge feature1", it will merge the "feature1" branch into the main branch.

In summary, Git is a powerful and essential tool for code version control. It allows you to track changes, collaborate with others, and keep your code organized. Understanding and using Git is a crucial skill for any front-end developer.

Now answer the exercise about the content:

What are the three main areas of Git?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Deployment of Front End applications

Next page of the Free Ebook:

90Deployment of Front End applications

3 minutes

Obtenez votre certificat pour ce cours gratuitement ! en téléchargeant lapplication Cursa et en lisant lebook qui sy trouve. Disponible sur Google Play ou App Store !

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text