First Week of The Hacktoberfest: 8 Top Questions Around Git

Ayu is a tech blogger, open source contributor & maintainer, and tech community enthusiast based in the Netherlands. She loves photography and iced coffee!
Search for a command to run...

Ayu is a tech blogger, open source contributor & maintainer, and tech community enthusiast based in the Netherlands. She loves photography and iced coffee!
No comments yet. Be the first to comment.
Hi friends π, I've been writing tech blog posts for a few years now. If you don't know me yet, English is my second language. My mother tongue is Indonesian, and I'm also surrounded by Dutch every da

I frequently receive messages from enthusiastic contributors who have completed 2 or 3 high-quality pull requests (PRs) in just 1 month. Theyβre proactive, their work is top-tier, and theyβve handled

A few months ago, I shared a story about building an automated open source portfolio using just my smartphone and an AI assistant while on vacation. My main goal was to stop the "spreadsheet struggle"

Recently, I read Bekah Hawrot Weigelβs blog post, "When 'Local' Went Global: The Pandemic Era of International Communities." As someone active in many online communities, I found it a bit sad, but I agree with her points and think they apply to open ...

Hacktoberfest is almost over. How has your contribution journey been so far? Are you confident about contributing to open source projects, or are you still struggling to find your way? If you're new to open source and still feel overwhelmed, that's c...

Hello Fellow CodeNewbies π,
The first week of Hacktoberfest 2021 has passed.
This month, I'm participating in Virtual Coffee's October monthly challenge, and the collaboration program at The Collab Lab is also starting.
These events give me lots of opportunities to learn Git by doing.
I made so many mistakes along this journey and got countless panic attacks π.
But I also asked many questions and got a lot of help.
I'm sharing my top 8 questions about Git in this article and the answers.
I hope they can help you if you have the same or similar questions as mine.
These are the tools that I'm using for working with Git. If you have different tools, there could be other commands or steps for you to do.
fork a repo?Before we start working on an open-source, we want to fork the original repo. This forked repo would be the repo we will make and push our changes to.
But why do we want to fork the original repo?
The open-source is no longer active or abandoned by its maintainers.
Let's say we want to learn about something. Then we found a repo that we want to learn from. But then we realize that this repo has had no update for ages.
There would be a big possibility that this repo is no longer maintained or deprecated. But we still want to try it out.
One way to do that is to fork the repo and work with this forked repo.
No authorization from maintainers.
Most open sources don't give us the authorization to make changes and push them directly to their repo.
That's another reason we want to fork the original repo.
After forking, we want to clone this repo instead of the original one.
origin and upstream mean?The naming in Git is pretty confusing (at least for me π ).
What is the difference between origin and upstream? Why are there commands such as git fetch origin or git fetch upstream? From where are we fetching?
Some opinions are saying it's a matter of conventional naming. But they are pretty much the same.
Both are remote repos but they are not the same.
origin
upstream
Because we want to avoid our pull request causing conflicts on the remote main branch, the remote main branch could also lose some merged changes without updating.
Before pushing our changes, ensure our main and feature branches have the same updates as the upstream.
Go to our forked repo on GitHub.
We will see a Fetch upstream button on the right side.

GitHub makes it easy for us to fetch the updates from the upstream.
Click this button, and we will get a dropdown menu.
When the Fetch and merge button is in inactive mode, there is no update on the upstream. If it's green, click it.
Until here, our origin repo has the same updates as the upstream.
Go to our terminal.
main branch with the git checkout main command.
git pull.Our main branch now has the same updates as the origin and upstream.
git checkout <branch-name>.git merge main.Now we can push our changes and create a pull request.
I'm self-taught and used to working alone. I have a terrible habit of not adding and committing my changes before I finish working.
We don't want to keep this habit when working in a team.
There are times when we want to go to other branches.
When we don't add and commit our changes, whatever changes we work on are carried onto the branch we go to.
And we don't want that.
The best time to add and commit our changes is as soon as we finish making some changes to our code, no matter how small it is.
This way, we can safely go to another branch when necessary. Besides, we can have a good history of what we're doing step by step.
Sometimes we want to save our changes but don't have an intention to commit them yet. In this case, we can run git stash.
I was merging a branch. Then I got some conflicts because someone else worked on the same file.

It gave me several options that I had to choose from on VSCode.
Which one we need to choose depends on our discussion with our teammates.
If we need to merge it soon and are unsure which one to choose, we can choose to Accept both changes to be safe.
One day when I worked on changes in a branch, it got so messed up. I wanted to delete this local branch and pull the branch from the remote repo to have a fresh branch.
We can do so by running these commands:
git branch -D <feature-branch-name> to delete our local branch.Then,
git checkout <future-branch-name> to pull the branch on the remote repo.We don't need to create a new branch as in git checkout -b <future-branch-name> when we want to pull an existing branch.
With git checkout <future-branch-name>, Git will check if we have that branch in our local repo.
It will look for the branch on the origin repo when it can't find that branch. And if it's founded, Git will pull that branch to our local repo.
We want to make sure that we enter the exact branch's name as in the origin repo.
git status?--force such as git push --force?As straightforward as the name, force means forcing any changes to a branch. It will ignore every warning.
Once we do git push --force, it will force push our changes and replace everything on the remote with our changes. The bottom line, we are deleting all history on the remote repo and replacing them with ours.
When we work in a team, this can cause trouble for the whole team.
There are some rare circumstances where we need to do this.
But beforehand, we have to make our team members aware that we will do it and go for it when everyone agrees.
My key takeaways after these experiences:
git stash when we only want to save our changes and want to continue working on them later.git status.--force as much as possible.Thank you for reading!
Last but not least, you can find me on Twitter. Let's connect! π