Q1. What is Git?
- GitHub makes it easy for developers to create and share code. Using free and open source software, your projects are hosted on the largest host of public projects – meaning other users can reach in and modify your code, or use it as a starting point for new development. Moreover, It provides reliable version control, collaboration, and deployment services that enable you to host your own projects with ease. And it's free!
Q2. How Git works? Explain the architecture of Git.
Git is a tool that helps developers keep track of changes made to their code. Developers can create a new "branch" to make changes without affecting the main code, and then "commit" the changes, which creates a snapshot of the code at that moment. They can also collaborate with other developers by working on a "remote" version of the code, which is hosted on a server and can be accessed by multiple people. Git allows developers to easily go back to earlier versions, and work together on the same codebase.
Git's architecture is based on a decentralised model which means that every developer has their own copy of the entire codebase and its history on their machine. Each change made is recorded as a "commit", which is a snapshot of the codebase. These commits are organised in a DAG (Directed Acyclic Graph) structure, which allows for easy navigation through different versions of the codebase. Git also uses "branches" as a way to separate different versions and "remote repositories" to collaborate with other developers.
Q3. Explain why Git is distributed?
- Git is a distributed version control system because it allows every developer to have their own copy of the entire codebase and its history on their own machine. This means that every developer has a full copy of the codebase and all its history, so if the central server goes down, developers can still work on the code and commit their changes. Additionally, it allows for more flexibility and faster performance as developers can commit their changes locally and push them to the remote repository when ready. It also allows for offline work, and in case of any network issue, developers can still commit and push their changes when they regain connectivity.
Q4. Explain Git workflow with image.
- Git workflow is a process that developers use to manage changes made to their codebase. The workflow starts with creating a new "branch" from the current version of the codebase. This allows developers to make changes without affecting the main code. Once the changes are done, developers can then "commit" the changes, which creates a snapshot of the code at that moment. Developers can then "push" the changes to a "remote" repository, which is a copy of the codebase hosted on a server that can be accessed by multiple people. Finally, the changes can be "merged" back into the main codebase with the help of pull requests.
Q5. List top 10 Git commands.
git init- Initialises a new Git repository
git clone- Creates a copy of a remote repository on your local machine
git add- Adds changes to the staging area
git commit- Creates a new commit with the changes in the staging area
git status- Shows the status of the working directory and the staging area
git diff- Shows the differences between the working directory and the last commit
git log- Shows the commit history
git branch- Lists all branches in the repository
git checkout- Switches to a different branch or commit
git merge- Merges changes from one branch into another