As a beginner git can be a little confusing but I promise as you continue to write code and make more repos you make you will very quickly become familiar with it. For the sake of brevity I won’t be covering the absolute basics of git— rather today explain a very quick way to collaborate with people and share code via git remote
The good news is if you’ve ever setup a git repo before congrats you’ve worked with remotes successfully. We pretty much always start with some kind of
git remote add origin <git repo url>
This is saying hello git setup a remote and we will call it origin ( this is done by convention also pretty logical since this represents the origin of our git repo ) nothing is stopping you from calling it potato but call this one origin. Then we supply the origin url and hit enter. Now we have the ability to push and pull code from this repo and you can visualize your remotes with the command:
git remote -v
When you do this you will see your git repo twice, why is deeper than this guide will cover. Just know that you will see the name you gave it followed by the url.
Now whenever we want to add changes to our origin we just have to commit them as usual — then git push <name> <branch> this case the name is origin and the branch is main. To grab some changes from the origin and get them locally we just do git pull <remote> <branch> again this would be git pull origin main to pull changes from the origin.
To rope this back to how you can collaborate on code using remote take this example. Person A and Person B start a project together and both setup their repos as normal, each with their own origin on their own github accounts with their own local versions. Finally you both decide you want to get the changes from each other — They send each other their urls:
Person A → Person B; Person B → Person A
You can do the same git remote command except this time were not setting up and origin point were setting up a remote for Partner X url.
git remote add <person x> <person x url>
It’s now as simple as Person A deciding they want the latest code from Person B and use the command git pull <person x> <branch>
git pull personB main; Person B:
git pull personA main
This was just an extremely basic guide to working on a project with a partner using git. You can take this and run but there is also a few resources to a further understanding of git. Here are the two I found the most helpful: