Unnecessary Git Quiz
Tags: opensource, git, linux, github
Published: 2024-02-19 15:54:40

### 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!***

---

- 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`

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
git blame -C -C         # This is the right
git blame -C -C -C      # But, this isn't wrong! (why?)
</pre>
</details>

---

- 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>`

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
git switch &lt;branch-name&gt;
</pre>
</details>

---
- 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)

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
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 &lt;branch-name&gt;` 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 &lt;your repo link&gt;`
  8. push to the repository, either `git push origin &lt;branch-name&gt;` or `git push my-origin &lt;branch-name&gt;`
  9. raise a PR to their repository, (Optionally, run CI tests on your local fork, and then raise a PR)
</pre>
</details>

---    

- 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?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git stash -u`
</pre>
</details>

---

- 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?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git blame /path/to/file` and ask the author about more details
</pre>
</details>

---

- What’s the difference between `git merge` and `git rebase`?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
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
</pre>
</details>

---

- 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?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git revert HEAD`
</pre>
</details>

---

- 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`

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git diff`
</pre>
</details>

---

- 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?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git cherrypick`
</pre>
</details>

---

- 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?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git checkout branc-name:/path/to/file`
</pre>
</details>

---

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

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git commit --amend`
</pre>
</details>

---

- 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?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
Add the folder in `.gitignore`
</pre>
</details>

---

- 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.

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
Do the following
  1. Add remote `git remote add my-origin <branch>`
  2. Push change `git push my-origin <branch>`
</pre>
</details>

---

- 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?

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
`git pull origin main`
</pre>
</details>

---

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

<details>
<summary><i><u>Answer!</i></u></summary>
<pre>
adding them to `git config` entries will be `user.name` and `user.email`
</pre>
</details>

---

Embark on an enlightening journey through the intricate world of payments. These blogs are your compass to navigate the complexities of the payment galaxy. 

As developers, we create a lot of value through the applications we build. Payments are the means to capture some of that value for ourselves. Surprisingly, the effort to set up a payments stack is often exaggerated. This is what we aim to solve at Hyperswitch by building a free and open payments switch. If you resonate with this vision, you can join the movement to help build an open payments ecosystem!

![contributors](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwbphgvpyilq2h1546h9.png)

**Learn more about how you can set up your own payments stack in minutes with [Hyperswitch](https://docs.hyperswitch.io/about-hyperswitch/readme)**

---

- Want to contribute? Check out some of our [good first issues here.](https://github.com/juspay/hyperswitch/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)
- Try Hyperswitch. [Get your API keys here.](https://app.hyperswitch.io/)
Happy reading!