Welcome to the Git quiz!

Here's a quick litmus test for anyone looking to contribute to Hyperswitch  or any open source repository in general. This quiz encapsulates basic concepts that you'd need to get started. Haffun!

1. In a recent commit someone created a new file, and moved functions from random files into this file (because modularity). Now it seems that there might be a bug in one of these functions, and the dev that created the file doesn't know the underline logic present in the functions, how can you quickly know who authored it?

[a] git blame

[b] git blame -C

[c] git blame -C -C

[d] git blame -C -C -C

Answer!Answer! git blame -C -C # This is the right
git blame -C -C -C # But, this isn't wrong! (why?)

2. Which of the following commands are used to go to a different existing branch?

[a] git branch <branch-name>

[b] git switch <branch-name>

[c] git branch -c <branch-name>

[d] git checkout -b <branch-name>

Answer!
git switch <branch-name>

3. Consider, if you have to raise a PR to a external open source repo, what are the steps that you will follow? (Consider the OSS repo is on github, mention the steps that are performed locally as git commands and that performed on github & anything else as simple points)

Answer!
Following are the steps of contributing to OSS repos
1. Find issue and communicate about possible solution.
2. Fork the repository
3. Clone it to your local setup.
4. Configure components mentioned in the `README.md`s
5. `git checkout -b <branch-name>` create a new branch for development
6. complete the development, commit the changes following the guidelines for commits as mentioned in their repository
7. add your personal forks origin, if you cloned before forking. `git remote add my-origin <your repo link>`
8. push to the repository, either `git push origin <branch-name>` or `git push my-origin <branch-name>`
9. raise a PR to their repository, (Optionally, run CI tests on your local fork, and then raise a PR)

4. You have made a few changes and added a few new files, turns out you have to start working on something else, so you need to keep everything that you have done aside, how will you do that?

Answer!
`git stash -u`

5. You are reading a file in your local git repository, and you wish to know more about a certain function you saw in it, but there is no documentation, how can you get information about it?

Answer!
`git blame /path/to/file` and ask the author about more details

6. What’s the difference between git merge and git rebase?

Answer!
git merge, ands a new commit to your new branch which gets the branch up-to-date with the branch that your are merging. git rebase on the other hand rebases the commits on top of the other branch. The following diagram explains it.
U----V----W----X---- (your current branch)
/ / <--- (the merge)
-A----B----C----D----F (branch to be merged)

git merge
U----V----W (branch after rebase)
U----V----W / (branch before rebase)
/ /
-A----B----C----D----F (branch to be merged)

git rebase

7. Oops, someone accidentally pushed a commit to your main branch and that’s breaking quite a few things, what would you do, if you want to get the main branch stable again?

Answer!
`git revert HEAD`

8. You have done some changes to your branch, you want to view those changes before committing them, what would you do to view what new code you have added.

[a] git log

[b] git show

[c] git diff

[d] git status

Answer!
`git diff`

9. You are working on a new feature, while testing you found out that the application isn’t showing any logs. Luckily, a collaborator mentioned she added a commit just to enable logging in her own branch, but it was a long time back and she had added more commits after that, what would you do?

Answer!>
`git cherrypick`

10. You are getting ready for deploying your project on cloud, but the server configuration file in your branch is amiss, once again a collaborator to the rescue, lets you know that he has a proper config in one of his commit but unfortunately the commit also has other changes. you want to do a dry-run of the config by getting the changes from that single file into your current branch, which git command can accomplish this?

Answer!
`git checkout branc-name:/path/to/file`

11. You have added a commit to your branch, the commit message looks something like, feat(db): add new label to customer database seems like it there are a few spelling mistakes, how can you fix the commit message?

Answer!
`git commit --amend`

12. You are maintaining a rust project on GitHub, and someone raised a PR to it with the binaries for the compiled rust project, but those are huge and we don’t need them. What can you do, so that now one in the future is able to commit /target directory to the repo?

Answer!
Add the folder in `.gitignore`

13. You had cloned your friends repository, and were working on it. You came up with a solid feature and committed it to your local branch, instead of sending the branch to his repository, you want to send it to your own fork of his repository on GitHub, list exactly 2 commands that will which when run in succession will allow this to happen.

Answer!
Do the following
1. Add remote `git remote add my-origin `
2. Push change `git push my-origin `

14. You are working on a branch and want to incorporate the changes made to the main branch. What command do you use to do this?

Answer!
`git pull origin main`

15. How will you make sure that your name and email appears on every commit that you make?

Answer!
adding them to `git config` entries will be `user.name` and `user.email`