Welcome to Git and Github

This documentation serves as your go-to guide for getting started with these essential tools. It covers everything from installation and setup to executing key commands and adhering to best practices for version control. With this guide, you can confidently navigate Git and GitHub whether you are working on a new feature, resolving bugs, or reviewing code.

What is a version control system?

Version control systems are used to manage the history of your code. They allow you to track changes to your files and collaborate with others. Version control systems are essential for software development.

Types of version control systems

There are three main types of version control systems (VCS) used in software development:

Local version control system:

These systems manage version control on a single developer's computer. All versions of a project are stored in a local database.

Examples: RCS (Revision Control System), SCCS (Source Code Control System).

Centralized version control system:

In CVCS, a central server stores all the versioned files, and developers access it to check out files for editing. Changes are committed back to the central server.

Examples: CVS (Concurrent Versions System), Subversion (SVN), Perforce.

Distributed version control system:

In DVCS, every developer has a complete copy of the repository, including the project's history. Changes can be made locally and synchronized with a remote repository as needed.

Examples: Git, Mercurial, Bazaar.

What is Git ?

Git is a Version Control System (VCS) that helps developers track and manage changes to files and code over time. It enables teams to collaborate efficiently on software projects by maintaining a history of modifications, facilitating experimentation, and resolving conflicts.

  • Git was created by Linus Torvalds in 2005 to develop Linux Kernel.

Why Git ?

  • Widely Used: Over 70% of developers rely on Git, making it the industry standard.

  • Collaboration: Enables developers to work together seamlessly from anywhere in the world.

  • Project History: Provides access to the complete history of changes for better tracking and auditing.

  • Version Control: Allows developers to revert to earlier versions of a project when needed.

Key features of Git:

  • Distributed Development: Every developer has a complete copy of the repository and they can make changes without any conflicts

  • Branching and Merging: Create isolated environments for new features using branches and merge them when ready

  • Complete History: Track who made what changes and when

  • Local Operations: Work offline with full version control capabilities

  • Data Integrity: Ensures code changes are tracked accurately

  • Staging Area: Review and organize changes before committing

  • Fast and Lightweight: Efficient handling of small and large projects

What is Github ?

GitHub is a web-based platform that uses Git, a version control system, to help developers manage and collaborate on code repositories. It allows users to host, share, and track changes to their code, serving as a central hub for software development projects.

Key Features of GitHub:

  • Version Control: Seamlessly integrates with Git for tracking changes.

  • Repositories: Centralized hosting for public and private projects.

  • Branching & Merging: Allows independent work and easy integration of changes.

  • Pull Requests: Facilitates code reviews and discussions before merging.

  • Collaboration: Tools for team communication and notifications.

  • Documentation: Markdown support for README.md and wikis.

Git and GitHub Installation and Setup

Git Installation on windows:

To install Git on your system follow these steps:

  • Visit the official Git website: git-scm.com.

  • Click on Download for Windows. This will automatically download the appropriate installer for your system.

Git installation on Linux :

For Debian/Ubuntu-Based Systems

Use the apt package manager to install Git:

For Fedora-Based Systems

Use the dnf package manager to install Git:

For Arch Linux-Based Systems

Use the pacman package manager to install Git:

Verify Installation

After installation, check the Git version to ensure it is correctly installed:

Git Configuration Guide

After installing Git, it’s essential to configure it to personalize your settings and optimize your workflow. Use the following steps to configure Git globally or per repository.

Follow these steps to configure Git:

Step to create GitHub Account:

  • Open your web browser and go to the GitHub homepage: github.com.

  • Click on sign up.

  • Fill in your details (choose a unique username for your account, enter a valid email address, create a strong password).

  • Verify your account (GitHub will ask you to complete a CAPTCHA to confirm you're human. Follow the instructions to verify.)

  • Confirm your email address

Repository in GitHub :

A repository on GitHub is a storage space where your project files are stored. It can contain various files, such as source code, documentation, configuration files, and even images. A repository helps in managing the development of a project by tracking changes made to the files over time.

Key aspects of a GitHub repository include:

  1. Version Control: GitHub repositories are powered by Git, a version control system that helps track changes to files, collaborate with others, and manage different versions of a project.

  2. Collaborative Work: Multiple people can contribute to a repository, with each contributor making changes in isolated branches. These changes can later be merged back into the main project.

  3. Issue Tracking: Repositories have an issue tracker that allows users to report bugs, suggest new features, or discuss problems related to the project.

  4. README: Most repositories include a README.md file, which typically contains information about the project, how to set it up, how to contribute, and any other relevant details.

  5. Public or Private: Repositories can be public (open to everyone) or private (accessible only to specific users or teams).

To create a repository on GitHub, follow these steps:

Step 1: Log in to GitHub

  1. Open GitHub in your browser.

  2. Log in to your GitHub account using your credentials. If you don't have an account, you'll need to sign up.

Step 2: Create a New Repository

  1. On the GitHub homepage, click the + icon in the upper-right corner of the page (next to your profile picture).

  2. Select "New repository" from the dropdown menu.

Step 3: Configure Your Repository

You will be redirected to a page where you can configure the details of your new repository:

  1. Repository Name: Enter a name for your repository (e.g., my-project).

  2. Description (optional): Add a short description of your project.

  3. Public/Private: Choose whether the repository should be public or private. If it's public, anyone can see it; if private, only you and those you invite can access it.

  4. Initialize with a README (optional): Check this option if you want GitHub to create a README.md file for your repository (usually a good idea to provide details about your project).

  5. Add .gitignore (optional): You can select a .gitignore template based on the programming language you are using (e.g., Java, Python, etc.) to exclude unnecessary files from version control.

  6. Choose a license (optional): If your project is open source, you can add a license to clarify how others can use your code.

Step 4: Create the Repository

Once you've filled in the necessary details, click the "Create repository" button.

Step 5: Start Adding Files

After creating the repository, you will be redirected to the repository page. Here you can:

  • Upload files manually via the GitHub interface.

  • Clone the repository to your local machine using the git clone command and push files from your computer.

Clone the repository :

If you haven't already cloned the repository, use the following command in your terminal or command prompt:

Replace <repository-url> with the URL of the repository you want to clone.

Navigate into folder : fter cloning, a folder with the same name as the repository will be created in your current directory. Use the cd (change directory) command to navigate into this folder.

For example, if the repository is named my-repo, run:

Basic Git Commands:

Here are some basic Git commands that you will use frequently:

  1. Git init : The command git init is used to create an empty Git repository.

  2. Git clone : This command is used to obtain a repository from an existing URL.

  3. Git add command : This command is used to add one or more files to staging (Index) area.

To add one file :

  • To add more than one file :

  1. Git commit command : Commit command is used in two scenarios. They are as follows.
  • Git commit -m : This command changes the head. It records or snapshots the file permanently in the version history with a message.

    Git commit -a : This command commits any files added in the repository with git add and also commits any files you've changed since then.

  1. Git status command : The status command is used to display the state of the working directory and the staging area.

  2. Git push command : It is used to upload local repository content to a remote repository.

    git push -all : This command pushes all the branches to the server repository.

  3. Git pull command : Pull command is used to receive data from GitHub. It fetches and merges changes on the remote server to your working directory.

  4. Git Branch Command : This command lists all the branches available in the repository.

  5. Git merge command : This command is used to merge the specified branch?s history into the current branch.

  6. Git log command : This command is used to check the commit history.