DEV Community

Cover image for GitHub for babies
Tammy Alemu
Tammy Alemu

Posted on • Originally published at tami.hashnode.dev

GitHub for babies

A Walk Around GitHub

What is GitHub?

GitHub is a web platform where people can store and share their computer code. It's like a big online library where programmers can upload their code and collaborate with others. It provides a place for developers to work together on projects, make changes to code, and keep track of those changes. GitHub makes it easier for people to work on code together, even if they are in different parts of the world.
Take, for instance, you and your friend had a startup, but you both need jobs for funding, so you were actively applying. Finally, that email came, and you got the job. It's remote. You celebrated with your friend and encouraged him to apply more. Down the line, he got one. Great news, but it's onsite, which means your friend has to relocate. It's great, right? You don't want to jeopardize his chances, but what happens to your startup?
Okay, cool. We can share codes on WhatsApp... WhatsApp? Not reliable. It's different time zones. How do you merge conflicts? (I'd explain that). How do you test? Definitely, it's going to impact user input.
That's where GitHub comes in. Not only can you edit codes, but it also keeps track of changes. Isn't that super cool? 😎


Why GitHub?

If you're a music lover, I can tell you have your playlist personally curated based on your preferences and taste. You can't wait to share that feeling with your buddy, so you share your editable playlist. But how do you refrain your friend from inputting abstract songs into the playlist? However, he knows your taste in music, but sometimes he can miss the mark, right? You don't want jazz on a blues playlist (I love jazz music, haha). How do you refrain from that? Hmmm.

That's a conflict right there, but you still want to share your playlist with your buddy, right?

Take GitHub as a playlist filled with lines of your code. You create the playlist, and he makes a copy of it to add more interesting blues. All you have to do is verify if they suit your taste. So, Git typically merges both playlists, and voila, you've got a better playlist.

In instances of conflict, what's the best way to resolve them?

All you have to do is create your own branch and roll your updates... But wait what is a branch? We don't have an HQ yet, its just a startup. Hahaha, in GitHub practices, the main branch is the original project, but you need a repository (repo for short) to do that. Now lets understand what's a repo is.


Understanding GitHub

  • Repository: Imagine a repository as a big box or folder where you keep all the important stuff for a project. It's like a central storage space where you can store and organize everything related to your project, such as documents, files, and even different versions of your work. It helps you keep things organized and accessible in one place. Just like you might have a folder on your computer for all your photos or documents, a repository serves as a dedicated place for your project's files.

  • Branch: Now, think of a branch as a different path or direction that you can take within that big box or folder. It's like having a separate area where you can work on specific changes or ideas without affecting the main project. Just like you can take a detour while traveling, a branch allows you to explore different ideas or make changes to your project without messing up the original version.

In simpler terms, a repository is like a big box where you keep everything for your project, and a branch is like a separate path or area within that box where you can work on different changes or ideas without affecting the main project, and there's so much fun things you could do with a repository, like cloning and initializing.

  • Cloning existing repositories refers to making a copy of an already existing Git repository. This allows you to have a local copy of the repository on your own computer, so you can access the files and make changes without affecting the original repository.

  • Initializing a repository within a project directory means starting a new Git repository within a specific folder that contains your project's files. By doing this, you tell Git to start tracking changes to those files and enable version control for your project.

In these examples, setting up a new Git repository is like creating a dedicated space for your project or hobby. Cloning existing repositories is like making a copy of someone else's work for your own use.
Initializing a repository within a project directory is like setting up a shared space where multiple people can work on different parts of a project and later bring everything together.


Working with GitHub

So back to our playlist we shared with your bud, how do we achieve this?

Here's how it works:

  • Start with the main branch: The main branch is like the original project. It contains the initial files and serves as the foundation for everyone's work (The main playlist).

  • Create your own branch: Before making any changes, you create your own branch. It's like having your personal copy of the playlist to work on. This way, you won't affect the main branch or your friends' work.

  • Make your changes: You start working on your branch, making edits, adding new features, or fixing issues. You can do whatever you want without interfering with others.(Basically adding or removing tracks).

  • Commit your changes: Once you're done with your changes, you commit them. Think of it as saving your progress. Git records the changes you made, like a snapshot of the project at that moment.

  • Share your branch: After committing, you push your branch to GitHub. It's like uploading your changes to a shared space where your friends can see them.

  • Repeat the process: The cycle continues as others create their branches, make changes, and collaborate. Git keeps track of all the changes, making it easy to see who did what and when.

By following this workflow, Git and GitHub enable smooth collaboration on projects. They allow multiple people to work on the same project simultaneously, track changes, provide feedback, and merge everyone's work into a unified whole. It's like teamwork with an efficient system to manage and integrate everyone's contributions.

what if conflicts arise while updating the playlist? He took out your favourite track or added an odd one?? Oh dang this doesn't sound good right?

Now you

  • Resolve conflict. In git Sometimes, two people may make conflicting changes to the same file(playlist). Git helps you identify these conflicts and resolve them. It ensures that everyone's work fits together smoothly. After identifying the conflicts and been satisfied with the resolutions(tracks on the playlist) you merge.

  • Review and merge: Now your friends can see your changes and provide feedback. They might suggest improvements or ask for modifications. Once everything looks good, your branch can be merged into the main branch, combining your changes with everyone else's work.

Sometimes the merge conflicts arises, don't worry let's figure it out.

Merge Conflicts:

  • Merge conflicts occur when Git cannot automatically merge the changes because they affect the same lines or sections of a file.

  • Git marks the conflicting parts in the file and notifies you about the conflict.

  • Conflict markers (like "<<<<<<<", "=======", and ">>>>>>>") are inserted to highlight the conflicting sections.

Best Practices for Resolving Conflicts:

  • Communicate: Coordinate with your teammates to understand their changes and ensure everyone is aware of potential conflicts.

  • Update frequently: Regularly pull the latest changes from the shared repository to reduce the chances of conflicts.

  • Review changes: Before merging branches, review your teammate's changes to catch any potential conflicts early.

  • Resolve conflicts locally: Whenever possible, resolve conflicts on your local machine before pushing the changes to the shared repository.

  • Use tools: Utilize Git's built-in tools or graphical interfaces that assist in visualizing and resolving conflicts.

  • Test after resolving: After resolving conflicts, test the merged code to ensure it functions correctly and as intended.

So does that mean my bud can merge playlist without me reviewing?

No he needs to ask you first..... In etiquette it's called polite request, in Git we call it the Pull request.

A Pull request is like raising your hand and asking someone to review your work before it becomes part of a bigger project.

When you finish your part, you want others to review it before it gets added to the final project. So, you create a pull request. It's like raising your hand and saying, "Hey, can someone take a look at what I've done? I think it's ready to be added to our project."

  • To create a pull request, you upload your branch with the changes to a shared platform like GitHub.

  • Your teammates are then notified about the pull request and can review your code, offer suggestions, ask questions, or request modifications.

Finally we have an updated playlist. Viola.

Top comments (0)