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
Solutions Architect at Corgineering.com
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.
This article is part of our Best Practices series. Check out our other articles.