Git basics
Git is a version control system for keeping track of text-based files in a collaborative project.
The files are stored centrally on a remote repository (often Github or Gitlab). The collaborators work on their own local repositories, which are their own copies of the remote repositories.
To get started, a new collaborator clones the remote repository, which creates a local repository for them.
When a collaborator wants to publish the local changes they made to specific files, they stage these files, then they commit the changes to their local repository. Finally, they push these changes up to the remote repository.
When a different collaborator wants to get the most recent version of the files, they can pull down the changes, which updates their local repository.
Each repository can have branches. For simplicity’s sake, let’s say there is a development branch (called dev) and a production branch (called main). The concept of branches applies both to remote and local repositories.
The main branch is the up-to-date stable version of the project. The dev branch is where new changes are made. When a collaborator is ready to update the main branch with these new changes, they merge the dev branch into the main branch on their local repository. Then they commit the changes to the remote repository.
Example scenario
Let’s look a what this might look like in practice with 2 characters - Joe, the new guy, and Jackie, the team lead.
*note in our case, Joe’s command is using the command “git add .” which stages all the files in his local repository (as opposed to specific ones).
Closing thoughts
Git is really useful, but personally took me a while to wrap my head around it. Both using git in real life purposes and writing this post has helped solidify the concepts for me.