Diving Into Git Collaboration

Diving Into Git Collaboration

Hint: Don't work in main...

Git basics

Even if you have done a very limited amount of coding, chances are that you have at least heard of Git. Git is the most commonly used version control system today. Essentially, Git allows you to make "checkpoints" during the lifespan of your coding project.

The reason Git is so popular is that it is relatively easy to start up and host your repository on a service such as GitHub. But what if you want to work with multiple people on the same project? Well as it turns out Git is the perfect tool for that as well. The only issue is that it requires a lot of planning and communication with the other members of your team.

I found this out firsthand while working on a group project called Structify (Check it out! )


Understanding Git Branches

So what is a Git branch? Well, as the name suggests, Git branches are like the branches of a tree. They allow your project to grow and adapt while keeping the main codebase (the tree trunk) stable. Branches allow you to work on different features or fixes without affecting the main codebase. To create a new branch, use the git checkout -b command. For example:

git checkout -b <'Name-of-your-branch'>

You can then switch to the new branch anytime using git checkout ( Note: if you have just created the branch using the code above, it should switch to that branch automatically! ) :

git checkout <'Name-of-your-branch'>

Now, you can make changes and commit them without impacting the main branch.

Pushing Branches and Creating Pull Requests

Once you've made changes to your branch, it's time to share your work with others. First, make sure you add all changed files, commit them, and finally push them to your GitHub repository:

git add .
git commit -m 'Descriptive Message'
git push

Notice when you git push to a branch your terminal tells you the correct push command to use. Make sure you run that code into your terminal as the normal git push wouldn't have done anything.

Now, it's time to create a pull request. A pull request is a request to merge your changes into the main branch. You can create one directly on GitHub by navigating to your repository and clicking the "Compare & pull request " button that should show up automatically if you have pushed a new branch to the repository.

Select your branch as the source and the main branch as the target. Add a title, description, and any relevant details. Review the changes and, when ready, click "Create Pull Request."

Understanding Merging and Handling Merge Conflicts

Merging is the process of combining changes from one branch into another. When your pull request is approved, you can merge it into the main branch. On GitHub, this can be done by clicking the "Merge Pull Request" button. In a perfect world, that's all you need to do. However, more likely than not, you'll run into some issues especially if your teammate merged their branch before you did yours.

Merge conflicts occur when Git can't automatically merge your changes because there are conflicting changes on the main branch. This is the reason why having solid communication between team members is ideal. For our phase 2 project at Flatiron School, my group set together at a table and handled the merges together as GitHub gives you a built-in merge conflict handler. This conflict handler shows you where the conflict is happening and how the different lines of code differ from each other.


Importance of Git Collaboration

While all of this may seem like a lot, having a good understanding of Git collaboration and just Git in general will make your life much easier. As software developers, there are times when building something by yourself is simply not feasible and so you will need to recruit other developers. Using Git or even some other version control system will be necessary for this and understanding even the basics will make your life so much easier.


Structify

As mentioned in the introduction, my group used all of the concepts mentioned in the post to create a website that is all about learning different data structures. As a group, there were oftentimes where having a meetup and discussing the general plan moving forward took longer than implementing the actual code. So, if you want to learn about some data structures or just want to have a look at the finished product, check out our website Structify!

( Some images for those who don't want to click on the link )