Best Practicesยท5 minutes read

Collaboration Over Version Control

Ever wondered how programmers store and collaborate without having to send files back and forth? Thatโ€™s where GitHub, GitLab, and many more come into play! These platforms allow developers to store code online, work together on projects, and keep track of every change.

Linas Kapoฤius

Linas Kapoฤius

Solutions Architect at Corgineering.com

October 1, 2024
Collaboration Over Version Control

Let's dive into the basics, plus some advanced tips for the seasoned devs. Don't forget to follow me or give this post a ๐Ÿ‘ if you find it helpful!

1๏ธโƒฃ ๐—ฆ๐—ฒ๐˜๐˜๐—ถ๐—ป๐—ด ๐˜‚๐—ฝ ๐—ฎ ๐—ฅ๐—ฒ๐—ฝ๐—ผ๐˜€๐—ถ๐˜๐—ผ๐—ฟ๐˜† A repository (or "repo") is like a project folder where all your code and its history are stored.

How-To: Create a new repository on GitHub/GitLab or another Git platform. You'll need credentials for these services. Follow the platform's instructions to create the repo.

Tip: It is possible to set up some platform specific CI/CD tools, so check them out because they are totally for free.

2๏ธโƒฃ ๐—–๐—น๐—ผ๐—ป๐—ถ๐—ป๐—ด ๐—ฎ ๐—ฅ๐—ฒ๐—ฝ๐—ผ๐˜€๐—ถ๐˜๐—ผ๐—ฟ๐˜† Cloning a repo means downloading a copy to your local machine so you can work on it. This is useful not just for your own work but also for downloading others' projects.

How-To:

git clone <repository-url>

Already Have Local Work? Link it:

git remote add origin <repository-url>

Tip: You can add multiple remotes to push to different repositories. For instance:

git remote add upstream <another-repo-url>

3๏ธโƒฃ ๐—ฃ๐˜‚๐˜€๐—ต๐—ถ๐—ป๐—ด ๐—–๐—ต๐—ฎ๐—ป๐—ด๐—ฒ๐˜€ Pushing uploads your local commits to the remote repository so others can see and work with your changes.

How-To:

git push origin <branch-name>

Set up upstream tracking to simplify future pushes (tip):

git push --set-upstream origin <branch-name>

4๏ธโƒฃ ๐—ฃ๐˜‚๐—น๐—น, ๐— ๐—ฒ๐—ฟ๐—ด๐—ฒ, ๐—™๐—ฒ๐˜๐—ฐ๐—ต Even experienced devs sometimes mix these up. Hereโ€™s a quick breakdown to make it clear:

๐—™๐—ฒ๐˜๐—ฐ๐—ต: Downloads changes from the remote repository but doesnโ€™t apply them to your work.

When to Use: Check for updates without changing your current work. Itโ€™s like asking "Whatโ€™s new?" without taking action.

git fetch origin

Advanced Tip: Use command below to fetch updates from all of the remote branches

git fetch --all

๐— ๐—ฒ๐—ฟ๐—ด๐—ฒ: Combines your changes with someone else's. More about branching on later posts.

When to Use: Combine work from different branches, like merging a feature branch into main.

git merge <branch-name>

Advanced Tip: For more rebasing type of guys use git merge --no-ff to ensure a merge commit is created, preserving branch history.

๐—ฃ๐˜‚๐—น๐—น: Combines fetch and merge in one step. It downloads changes and merges them into your current branch.

When to Use: Bring in remote changes when you're ready to update your current branch. Be ready to handle merge conflicts if they arise.

git pull origin <branch-name>

Advanced Tip: Use git pull --rebase to reapply your changes on top of the fetched branch, maintaining a cleaner history.

Blog image

This article is part of our Best Practices series. Check out our other articles.