1. What is Git?

  • Git is a distributed version control system that enables efficient and robust version management of files and source code, allowing multiple individuals to work on projects concurrently.
  • It was created by Linus Torvalds in 2005.
What is Git?

2. Why use Git?

  • Git allows efficient handling of projects by providing features like branching and merging, ensuring versioning and allowing each developer to have their own local repository, enhancing security and flexibility.

3. What is a commit in Git?

  • A commit in Git is the action of writing or merging data (typically source code) to the local repository. Each commit has a unique ID that allows developers to keep track of the changes made.

4. What is Git and how does it differ from GitHub?

  • Git is a distributed version control system used for tracking changes in source code, while GitHub is a web-based platform for hosting and collaborating on Git repositories.

5. Explain the purpose of a README file in a GitHub repository?

  • A README file provides information about the project, its purpose, and instructions for setting it up and using it.

6. How do you initialize a Git repository in a local directory?

  • You can run the "git init" command in the directory to create a new Git repository.

7. What is the purpose of the gitignore file?

  • The .gitignore file specifies which files or directories should be ignored by Git, typically to exclude build artifacts, temporary files, and sensitive information.

8. How do you add changes to the staging area in Git?

  • Use the git add command to add changes to the staging area. For example, git add filename stages changes in "filename."

9. Explain the difference between git pull and git fetch?

  • git pull fetches changes from a remote repository and merges them into the current branch. git fetch only retrieves changes from the remote repository but "doesnt" merge them

10. What is a Git branch, and how do you create and switch between branches?

  • A branch in Git is a separate line of development. You can create a new branch with git branch branchname and switch to it with git checkout branchname.

11. How do you resolve merge conflicts in Git?

  • To resolve merge conflicts, edit the conflicted files manually, remove conflict markers, add the resolved files to the staging area, and then commit the changes.

12. Explain what a Git rebase does and when you might use it?

  • Git rebase moves or combines a series of commits to a new base commit. Its often used to keep a clean commit history by incorporating changes from one branch into another.

13. What is a pull request in GitHub, and how is it different from a merge request?

  • A pull request (PR) and a merge request (MR) are essentially the same concept: they are requests to merge code changes. GitHub calls them pull requests, while GitLab and some other platforms call them merge requests.

14. How do you squash multiple commits into one in Git?

  • You can squash commits using an interactive rebase with the git rebase -i command and marking commits as "squash" or "fixup."

15. Explain the purpose of Git submodules?

  • Git submodules allow you to include other Git repositories as subdirectories in your own repository, helping you manage external dependencies.

16. What is Git bisect, and how can it be used to find a specific commit that introduced a bug?

  • Git bisect is a tool for binary search of commits to identify the one that introduced a bug. You mark known good and bad commits and let Git find the culprit.

17. What is Git cherry-pick, and when might you use it?

  • Git cherry-pick allows you to pick a single commit from one branch and apply it to another. Its useful for applying specific changes without merging entire branches.

18. Explain the purpose of Git hooks.?

  • Git hooks are scripts that can be triggered at various points in the Git workflow, such as pre-commit or post-receive, to automate tasks or enforce policies.

19. How do you revert a commit in Git?

  • You can use the git revert command followed by the commit hash to create a new commit that undoes the changes introduced by the specified commit

20. What is a Git tag, and how do you create and delete tags?

  • A Git tag is a reference to a specific commit. You can create tags with git tag and delete them with git tag -d.