- Git is a free and open-source distributed version control system designed to manage source code and other file revisions.
- Using Git, programmers have the ability to track changes made to their codebase over time, collaborate with other team members, and restore previous versions of their work when needed.
A git repository is a central location where all the files and directories for a project are stored, along with their complete version history.
Git - Git is a distributed version control system that allows developers to manage and track changes to their codebase
GitHub - GitHub is a web-based platform that provides hosting for git repositories and also offers a range of collaboration tools.
The git clone command enables you to create a local copy of a remote repository.
$ git clone REPO_URL
----------------------
$ git clone https://github.com/surbhidighe/Git-interview-questions.git
'git init' command is used to initialize an empty git repository
- A branch is a lightweight movable pointer to a commit
- It provides a way for developers to work on different parts of a project without affecting each other's work
- It helps to keep the codebase organized and reduces the risk of conflicts between changes made by different people.
We can use below command to create a new branch -
$ git branch <BRANCH_NAME>
If you want to switch to an existing branch, you can use 'git checkout' command and pass the name of the branch you want to switch to.
$ git checkout feature
output - Switched to branch 'feature'
If you want to switch to a non-existing branch, you will need to use the -b option. It will first create a new branch and then switch to that branch.
$ git checkout -b bug-fixes
output - Switched to a new branch 'bug-fixes'
Git won't let you delete the branch you're currently on, so you'll need to switch to another branch before deleting the one you want to delete.
Delete a branch locally
$ git branch -d <BRANCH_NAME>
Delete a branch remotely
$ git push <remote_name> --delete <BRANCH_NAME>
OR
$ git push <remote_name> :<BRANCH_NAME>
To list all remote branches
$ git branch -r
To list all local branches
$ git branch
NOTE : the current local branch will be marked with an asterisk
To list all local and remote branches
$ git branch -a
The "git --version" command is used to check whether git is installed on the system or not.
To see the most recent commits in git, you can use the "git log" command.
To see 5 most recent commits in git, you can use the "git log -5" command.
You can set your git username and email globally using the below commands
To set username
$ git config --global user.name "NAME"
To set email
$ git config --global user.email "EMAIL ID"
You can set your git username and email for a specific repository using the below commands
To set username
$ git config user.name "NAME"
To set email
$ git config user.email "EMAIL ID"
main - It is the default branch. It contains the latest stable version of the code.
Feature - It is created to develop a new feature or functionality.
Release - It is created to release a new version of your software.
Hotfix - It is used to quickly fix critical bugs or issues that are impacting the production environment.
The staging area is like a container that stores information about the changes you made to your files. It helps you decide which changes to include in your next commit.
'git add' command is used to add changes to the staging area.
To stage a file named "demo.js"
$ git add demo.js
To stage all files
$ git add .