- Difference between centralised and distributed version control system?
-> Centralized version control: A single copy of the project is stored in a central location, such as a server. Programmers commit their changes to this central copy.
Eg : SVN
Distributed version control: Each developer clones a copy of the project's repository to their own computer, so each developer has a local copy of the project's history
Eg : Git
In centralised there is single point failure so people mostly use the git nowadays.
- Why git is called Version Control System ?
-> Because it helps you track different versions of your code and collaborate with other developers.
- Diff btw git and GitHub ?
-> Git is a version control system that lets you manage and keep track of your source code history. GitHub is a cloud-based hosting service that lets you manage Git repositories
- Branches and types ?
-> Main/ master , feature, release, hotfix.
Main/Master: The primary branch where the stable and production-ready code lives; all completed features, fixes, and releases are merged here.
Feature: A branch created to develop a specific feature or functionality; it is merged into the main or develop branch once the feature is complete.
Release: A branch used to finalize and prepare the code for production release, including bug fixes and final testing, before merging into the main branch.
Hotfix has been used in case like user come with the bug after release of 2 or 3 days and you need a temporary branch that needed to fix the bug.
- What has been included in the .git folder ?
-> hooks − This folder contains script files. Git hooks are the scripts that are executed before or after events like commit, push etc.
objects − This folder represents an object database of Git.
config − This is the local configuration file.
refs − This folder stores information about tags and branches.
HEAD − This file stores reference to the current branch. It points to the master branch by default.
index − This is a binary file and stores staging information
- Git clone vs fork ?
-> Clone create a local copy of the repository or code of other developer on the other hand fork will create a new repository coping the code of the other developer using the distributed functionality.
- Git merge rebase and cherry-pick
-> cherry-pick : use the merge the specific commit using its commit id . syntax : git cherry-pick
rebase : use to merge the branch with linear order of commit on the other hand in the merge the branch commit will be after the main commit
- Git fetch vs pull ?
-> Fetch use to download the code from remote to local without merging it to the current working directory on the other hand pull with merge the code to the current working directory.
- What is git stash ?
-> The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.
- What is webhook ?
-> A webhook in GitHub is a mechanism that allows GitHub to automatically send data to a server when specific events occur in a software system
Life Cycle
Important git command :
git init
: Initializes a new Git repository in the current directory.git remote add origin <url>
: Links the local repository to a remote repository at the given URL.git add .
: Stages all changes in the current directory for the next commit.git commit -m "message"
: Commits staged changes to the repository with a descriptive message.git push
: Uploads local commits to the remote repository.git clone <url>
: Creates a local copy of a remote repository.git branch <branch_name>
: Creates a new branch with the specified name.git checkout <branch_name>
: Switches to the specified branch.git checkout -b <branch_name>
: Creates a new branch and switches to it immediately.git log --oneline
: Displays a compact, one-line summary of commit history.git reset --hard/soft <commit_id>
: Moves the branch pointer to a specific commit, optionally keeping (soft) or discarding (hard) changes.git merge <branch_name>
: Combines changes from the specified branch into the current branch.git rebase <branch_name>
: Reapplies commits from the current branch onto the specified branch to create a linear history.
Source: View source