Git is a distributed version control system (DVCS) that helps you track changes in your codebase, collaborate with others, and manage different versions of your project. It’s widely used in software development to maintain code quality, enable collaboration, and track the history of changes. It was created by Linus Torvalds in 2005 and has since become one of the most widely used version control systems in the software development industry.

Install

To install Git on a Mac, you can follow these steps:

  1. Using Homebrew (Recommended): Homebrew is a popular package manager for macOS that makes it easy to install and manage software. If you don’t have Homebrew installed, you can install it by following the instructions on the Homebrew website: https://brew.sh/

    Once you have Homebrew installed, open a terminal and run the following command to install Git:

    brew install git

  2. Using Xcode Command Line Tools: If you have Xcode installed, you can install the Xcode Command Line Tools, which include Git. Open a terminal and run the following command:

    xcode-select –install

    Follow the prompts to install the Command Line Tools.

  3. Download and Install from Git’s Official Website: You can also download and install Git directly from the official Git website. Here’s how:

    1. Open a web browser and go to https://git-scm.com/download/mac.
    2. Click the download link to download the macOS installer.
    3. Once the download is complete, open the downloaded file (it’s usually a .dmg file).
    4. Follow the installation instructions provided in the installer.

After you have installed Git, you can verify the installation by opening a terminal and running the following command:

git –version

Glosary

Repository (Repo): A Git repository is a collection of files and directories, along with metadata that tracks the history of changes made to those files. It contains a complete record of all commits, branches, and tags, allowing you to view, compare, and revert to previous versions.

To start a new Git repository, simply navigate to your project folder in the command line and execute the following command: “git init”

Commit: A commit is a snapshot of the changes made to the files in your repository. Each commit has a unique identifier and includes information about the author, timestamp, and a message describing the changes.

To make a commit, first add the files you want to include in the commit using the “git add” command, and then use the git commit command to create the commit.

Branch: A branch is a separate line of development within a repository. Developers can create branches to work on new features or fix bugs without affecting the main codebase. Once the changes on a branch are tested and reviewed, they can be merged back into the main branch.

Basic Git Commands:

git init: Initialize a new repository.

git add file: Add a file to the staging area for the next commit.

git commit -m “message”: Create a commit with the staged files and a descriptive message.

git status: Show the current status of files in the repository.

git log: Display the commit history.

git diff: Show the uncommitted differences between the current files and the latest commits.

git pull: Fetch and merge changes from a remote repository.

git push: Send local changes to a remote repository.

git clone url: Clone a remote repository to your local machine.

git branch: List branches and show the current branch.

git checkout branch_name: Switch to the specified branch.

git merge branch_name: Merge a branch into the current branch.