iRevolution Docs

Git

Master the fundamentals of version control with Git.

Introduction

Git is a tool that keeps track of changes to files, lets you work together with others, and saves a history of your project. This guide explains the basics you need to start using Git, especially how to work with branches.


Installation

Windows

  1. Open your web browser and go to https://git-scm.com/download/win.
  2. Download the installer (the file ends with .exe) and run it.
  3. Follow the on‑screen prompts – the default options are fine for most users.

macOS (no Xcode, no Homebrew)

  1. Download the official Git installer from https://git-scm.com/download/mac.
  2. Open the downloaded .pkg file and follow the installer prompts to complete the installation.

Linux – Ubuntu, Arch, Fedora

DistributionInstall Command
Ubuntu (or Debian‑based)sudo apt-get update && sudo apt-get install git
Arch Linuxsudo pacman -Syu git
Fedorasudo dnf install git

After installing, verify the version (this will always show the most recent version you just installed):

git --version

Configure Your Identity (once, after installing)

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

These details appear in every commit you make.


Getting Started

Clone an Existing Repository

git clone https://gitlab.com/username/repo.git

Replace the URL with the address of the project you want to copy.


Basic Workflow

  1. Check status – see what changed:
    git status
  2. Stage changes – tell Git which files to include in the next snapshot:
    git add <file>
    # or add everything
    git add .
  3. Commit – record a snapshot with a message:
    git commit -m "Add a clear, short description"
  4. View history – see past commits:
    git log --oneline --graph --decorate
  5. Push – send your commits to the remote repository:
    git push origin <branch>
    For a new branch you must use:
    git push --set-upstream origin <branch>
  6. Pull – fetch and integrate changes from the remote:
    git pull --rebase
    This updates your local branch with the latest changes.
  7. Handle conflicts – if a conflict occurs during merge or pull, Git will mark the conflicting files. Edit the files to resolve the conflicts, then stage the resolved files and continue:
    # after editing conflicted files
    git add <resolved-file>
    git commit   # or git rebase --continue

Branching

Branches let you work on separate ideas without affecting the main line of development.

Create a Branch

git branch feature/login

Switch to a Branch (newer command preferred)

git switch feature/login

You can also use git switch -c feature/login to create and switch in one step.

Merge a Branch

When the work on a branch is finished, bring it back into the main branch:

# First, go to the main branch (often called "main" or "master")
git switch main
# Then merge the feature branch
git merge feature/login

Git will automatically combine the changes if possible. If there are conflicts, Git will tell you which files need manual fixing.

Rebase (optional, for a cleaner history)

git switch feature/login
git rebase main

Rebasing rewrites the commits so they appear as if they were created directly on top of the latest main branch. Only rebase branches that no one else is using.


GitLab Merge Requests

In GitLab, you use Merge Requests (MR) to propose changes and have them reviewed before they are merged into the main project.

  1. Push your branch to the remote repository.
  2. Open the Merge Request: GitLab will often show a link in the terminal after you push, or you can go to the project page on GitLab.
  3. Review & Merge: Team members review your code, leave comments, and eventually merge the branch when it is ready.

Best Practices

  • Commit often – small, focused commits are easier to understand.
  • Write clear messages – a short title (≈50 characters) and, if needed, a longer description.
  • Keep branches short‑lived – merge or delete them once the work is done.
  • Never rebase a branch that is already shared with others.
  • Use a .gitignore file to keep unwanted files (build artifacts, secrets) out of the repository.
  • Run tests before merging to catch problems early.

Glossary

  • Repository (repo) – a folder that Git tracks.
  • Commit – a snapshot of the repository at a point in time.
  • Branch – a parallel line of development.
  • Remote – a version of the repository stored on another server.
  • Merge – combining changes from one branch into another.
  • Rebase – re‑applying commits on top of another base commit.
  • HEAD – the current commit you are working on.

On this page