Collaborating on GitHub using a Shared Repository

Kenny Yoon
4 min readJun 24, 2021

--

GitHub is one of the most common ways to collaborate with other developers. It is a platform that integrates ‘git’ to allow users to host shared git repositories. Then what is ‘git’? Git is an open-source “version control” tool developed in 2005 by a group of developers. Check out the documentation here to learn more about git.

Using GitHub, there are two main methods of collaboration:

1. The Shared Repository Model
This model is used for most small projects that have fewer collaborators or when the collaborators are working within the same physical space. All collaborators would have push and pull access to the main branch, which makes workflow much faster yet risky. I will dive deeper into this model later on in this post.

2. The Fork and Pull Model
This model is based on the concept of having an “owner” who assigns push/pull rights to the “collaborators”. This hierarchy allows workflow to be more reliable yet slower. To learn more about this model, check out the blog here.

In this blog, I will go over the basic shared repository model and the git commands that help you navigate through its workflow. First, you need to make a GitHub repo. If you are yet unsure of how to make one, look into this documentation. Next, you would need to navigate to settings=>manage access=>invite a collaborator. This would allow the added collaborators to clone your repository.

For collaborators to clone the repository: they would need to click the green “⬇️Code” button and navigate to the SSH option, copying the url that is displayed(there is a shortcut button to copy on clipboard). Then, on their terminal, collaborators should navigate to the location they would want to copy the project in and type in ‘git clone [replace with copied url]’. This should make a local copy of the repository on one’s computer.

git add, commit, & push

The key commands for the shared repository model is add, commit, push. ‘git add [replace with filename]’ prepares the file on your local repository for future commands. (‘git add .’ automatically adds(prepares) files that have not been added yet or that have been altered since the last push.) Using ‘git commit -m “[replace with commit msg]”’, one is able to take ‘snapshots’ of the files that were previously added. The content of your ‘commit msg’ does not affect the way your files are updated, but rather is a marker to help you track your file updates.The ‘git push’ command then updates the remote repository on GitHub with your files that have been committed.

After making big or small file updates, you would be able to use the add, commit, & push commands to upload your changes for your collaborators to continue building on.

git pull

In order for collaborators to update their local repositories to incorporate changes that have been ‘pushed’, they would ‘git pull’. Pulling acts as a ‘downloading’ of the files that have been uploaded to GitHub. Before updating your files, collaborators should make sure that they have “pulled” the most recently pushed version from the GitHub repository.

merging conflicts and how to resolve them

Merging conflicts can happen when more than one person starts working on the same files within a repository.

For example, two people pull the most recent ‘version A’ of a repository and both start editing the ‘example.js’ file. Collaborator 1 will be able to git add, commit, and push without having any trouble. However, after Collaborator 1 pushes his/her version, Collaborator 2 will face an error when attempting to push his/her own ‘example.js’ file.

After the initial push from Collaborator 1, Collaborator 2 would now be “editing an outdated version of the file”. Git does not allow you to update files by ‘skipping’ versions. Git allows you to tackle this ‘conflict’ by merging branches. Collaborator 2 will be asked to go over the ‘conflicting differences’ from Collaborator 1’s version. After implementing the changes on a text editor, Collaborator 2 can then git add, commit, and push to “resolve the conflict” and merge the file versions.

git status

The ‘git status’ command allows one to check if he/she currently has the most recent version of the repository. This is extremely useful because it allows the collaborator to prevent merging conflicts as it is not the most efficient workflow under the shared repository model.

git log

This command prints out the list of commits that have been pushed to the repository on one’s terminal.

--

--

No responses yet