Webdev

What is Git?

Git is a tool used to keep track of changes to files, especially the code of projects. It is termed a distributed version control system because it allows multiple people to work on the same project, even if they are not connected to a common server.

Created by Linus Torvalds in 2005 for the development of the Linux kernel, Git helps you manage changes to your code over time. It keeps track of every change or update, so you can always look back at previous versions or undo mistakes if needed.

Features of Git

Git workflow


Reasons to Choose Git

Steps to Setup Git

  1. Install Git: Download and install Git from the official Git website.
  2. Configure Git: Set up your username and email.
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    
  3. Create a Repository: Initialize a Git repository in your project directory.
    git init
    
  4. Make Your First Commit: Add files to the staging area and commit your changes.
    git add .
    git commit -m "Initial commit"
    

Basic Git Commands

Advantages of Git

Disadvantages of Git

Git Workflow

A common Git workflow includes:

  1. Clone Repository:
    git clone git@github.com:username/repository.git
    
  2. Create Branch:
    git checkout -b feature-branch-name
    
  3. Check Status:
    git status
    
  4. Stage Changes:
    git add filename or git add .
    
  5. Commit Changes:
    git commit -m "Add feature X"
    
  6. Push Branch:
    git push origin feature-branch-name
    
  7. Create Pull Request: On GitHub/other service.
  8. Update Local Repository:
    git checkout main
    git pull origin main
    
  9. Delete Branch:
    git branch -d feature-branch-name
    git push origin --delete feature-branch-name
    

Git – FAQs

What is Git and why is it used? Git is a distributed version control system that allows multiple people to work on the same project without interfering with each other’s changes. It helps manage and track changes to code, facilitate collaboration, and handle project histories efficiently.

What are branches in Git? Branches are used to manage and organize different lines of development within a project. They allow you to work on different versions of your project simultaneously.

What is a repository in Git? A repository is a storage space where your project’s files and their history are kept. It includes all files and directories related to your project, as well as their change history. Repositories can be local or remote.

What is a Pull Request (PR) in Git? A Pull Request (PR) is a request to merge changes from one branch into another, typically from a feature branch into the main branch. It allows team members to review and discuss the changes before integration.

What is the difference between Git and GitHub? Git is the version control system that tracks changes in your code and manages different versions. GitHub is a web-based platform that uses Git to provide cloud storage for repositories and collaboration tools.


NEXT -> Working with Git.