DEV Community

Cover image for My guide to effectively using git and GitHub for collaboration version control.
Sven Herrmann
Sven Herrmann

Posted on

My guide to effectively using git and GitHub for collaboration version control.

You probably use Git and GitHub frequently as a developer for version control and teamwork πŸ‘. However, the abundance of tools and settings accessible can make it simple to develop undesirable habits or feel overwhelmed. The best practices for using Git and GitHub to enhance your productivity and facilitate cooperation with others will be covered in this post.πŸ‘‡

Let's first go through the fundamentals of GitHub and Git. Git is a distributed version control system that enables you to work with others and track changes to your code. Web-based platform GitHub offers extra services like issue tracking, pull requests, and project management in addition to using Git as its foundational technologyπŸ’₯.

Branching is one of the most crucial ideas in Git. To work on a new feature or solve a bug, for example, you can create various versions of your code using branching. Using a master branch for your production-ready code and different branches for each new feature or bug repair is a standard branching technique. As a result, you can work on several improvements at once without affecting the primary codebase.
You'll use a pull request when you're prepared to integrate your modifications back into the master branch. You can ask someone else to examine your changes and give them the go-ahead for merging by submitting a pull request.

This is a crucial phase in the cooperation process since it enables other programmers πŸ’Ό to evaluate your code and offer suggestions before it is merged into the main branch.
The idea of code review is another crucial one. Code review is the process of having other developers examine your code to find potential problems, make it easier to read and maintain, and make sure it complies with accepted practices. Pull requests, Gitlab, Gerrit, and other tools can all be used for code review.

Maintaining concise and orderly commits is essential when using Git and GitHub. When you commit a lot of code at once, it might be challenging to figure out what changed and why. Instead, make an effort to divide your modifications into smaller, easier-to-understand portions.

In order for people to understand the objective of each commit, be careful to write clear and detailed commit messages.πŸ’
Finally, understanding merge conflicts and how to overcome them is crucial. When two or more branches make modifications to the same lines of code, a merge conflict arises. You must examine the conflicting code and choose which modifications to preserve and which to reject in order to settle a conflict.

πŸŽ‰πŸŽ‰πŸŽ‰
In conclusion, Git and GitHub are strong tools that can improve your ability to collaborate and manage your code. You can streamline your workflow and facilitate teamwork by adhering to best practices including branching, pull requests, code review, and commit management.

Additionally, it's crucial to set standards and GitHub and Git usage rules that the entire team can adhere to if you're working in a team.

If you take one point from this article than remember git and github are not the same. Git is a version control system that lets you manage and keep track of your source code history. GitHub is a cloud-based hosting service that lets you manage Git repositories

Git Commands:

  • Creating a new branch: $ git branch new-feature

  • Switching to an existing branch: $ git checkout new-feature

  • Merging changes from a branch into the master branch using a pull request: $ git checkout master
    $ git pull origin new-feature

  • Reviewing the difference between two branches: $ git diff branch1 branch2

  • Committing changes: $ git add file1.txt file2.txt
    $ git commit -m "Fixing a bug in file1 and file2"

  • Pushing your changes to a remote repository: $ git push origin new-feature

  • Resolving merge conflicts: $ git pull origin master

It's important to remember that the commands listed above are only examples, and their precise applications may change based on the situation.
Additionally, those instructions are for command-line use; if you prefer to use GUI clients like GitKraken, Tower, or SourceTree, the procedure may alter slightly but the principles remain the same.

Help wanted: What do you think about emojis in the text?
Should I use it or better only plain text?

Top comments (1)

Collapse
 
codewithbernard profile image
Bernard Bado

I love that you pointed out one thing: It's difficult to know what changed and why when committing big blocks of code.

That's why I built AI code review assistant that tackle this problem, by writing helpful code summaries to your pull request.