Version Control & Collaboration With Git & GitHub

#git   #github   #versioncontrol  

Hello 👋 and welcome, I’m undergoing a refinery process with The Startup Intern. During this process, I’ll be provided with study resources and tasks that will help solidify my learning. On successful completion of this process, I’ll be assigned to an organization as a backend developer intern. Kindly check out The Startup Intern on their website or on Twitter to know more about them and what they do. 🤝

This article is based on task 3 and here is my previous article.

Back To The Topic

Collaboration and contribution to projects are day to day activities of every programmer/software developer, it is the job. Every developer working in a team is assigned some issues/features that will make up a cool software application and are expected to solve problems, keep code versions/history, receive and share features from and to other developers.

This process of collaboration and contribution if done with the use of a floppy disk/USB hard drive does not guarantee data integrity and may result in conflicts (of code and developers) which in turn slow down development, hence the need for an efficient version control system.

Git! a solution 💡

But first, what is version control?

Version control is a way programmers track changes to development. It is the management of changes to documents, computer programs, large websites, and other collections of information. It is an essential skill that every software developer/programmer must learn.

Ok, now what is Git?

Git is a free and open source widely used version control system with a nice workflow that ensures everyone on the team works and collaborates on the same project without causing any error. It is a tool that tracks the changes in code/project. Git offers speed, efficiency, and data integrity of software development.

Open Source?

Open source control allows multiple devs. to work on a project from a different location. e.g. google docs allow different people to collaborate on a file.

GitHub

GitHub is a website where all git repository is hosted, it is a free hosting platform for version control and collaboration. Local repositories through some efficient workflow (with Git) are uploaded to the remote repository (GitHub). Being online makes it easier to collaborate with other programmers from anywhere and also to organize projects into portfolios to show to potential employers.

Repository is a collection of various version of different files of a project.

It is important to note Git is not GitHub. In Simple terms, Git is a version control system that lets you manage and keep track of your source code history while GitHub is a cloud-based hosting service that lets you manage Git repositories.

Getting started with Git and GitHub, I used the video tutorials provided as a resource for me as a guide. Git also provides an official documentation, Likewise GitHub which the documentation can be found here.

Essentials of Git 📕

The essentials of Git are the necessary terms and commands every developer must know to get them going. They are pretty much the basic commands that are used when starting a project from scratch or to make contributions to an existing project.

  • Init: meaning initialization is a way of starting a new project with Git. Command line “ git init ” creates a new Git local repository.
  • Clone: this is targeting an existing remote repository and then creating a local copy. Command line “ git clone ‘repository address’ ” is used to clone a hosted repository to the local machine/repository.
  • Branch: is an independent line of development created to encapsulate the changes when working on a new feature or bug fixes etc. To create a new branch, the command line “ git branch branchName ” is used.
  • Checkout: is navigating between the branches created within a repository. To navigate from one branch to another, the command line “ git checkout branchName ” is used. Git also provides a multi-level one line command “ git checkout –b branchName ” of creating a new branch and navigating into the newly created branch.
  • Add: is the addition of new or changed files in your working directory to the staging area. It is the saving of a snapshot of the current project state to the staging area. Command line “ git add fileName ” is used to move a file to the staging area while “ git add . ” is used to move all the files in a working directory to the staging area. N.B: The staging area contains files that are going to be part of the next commit.
  • Status: displays the state of the working directory and staging area. It is used to track whether there are new changes and if the changes have been staged for commit. For this, the command line “ git status ” is used.
  • Commit: is a record of the changes (snapshots) in the local repository. It is used to capture all snapshots along with a brief description or message. To Commit, command line “ git commit –m ‘description’ ” is used.
  • Log: is a list of all the commits to a repository. It contains the hash, the message associated, and more metadata of each commit. Command line “ git log ” is used to see the history of commits to a repository.
  • Push: is when the records (commits) of changes in the local repository are uploaded to the remote repository. From a branch, command line “ git push ” is used for this act.
  • Pull Request: this is a method of submitting contributions to an open development project. It is a way to tell other developers or contributors about changes you have pushed to a branch in a hosted repository such as GitHub. Although there is a command line to create a pull request (PR) from the local repository, it is much better and easier to create a PR from the GitHub website. There is a documentation here on how to.
  • Merge: is combining two branches, it is taking the content of a source branch and integrating them with a target branch. In this process, only the target branch is changed while the source branch history remains the same. To perform a merge, navigate to the target branch and then use the command line “ git merge sourceBranch ”
  • Pull: is downloading content from a remote repository into a local repository. Pull immediately update the local repository to match the downloaded content. To pull remote contents into a branch, navigate into the branch and then use the command line “ git pull ”.

Other essentials are; resetting staging and commit, deleting changes, checking change differences, stashing, rebasing, resolving merging conflicts, and more. Git provides an how to official documentation of all its command, also I found a cheat sheet for the essential commands here. Learning Git is also a great way to learn the command line.

Git Workflow 👨‍💻

The workflow steps are a recipe for how to use Git to accomplish work in a consistent and productive manner. It is a branch-based recommendation that encourages developers to leverage Git effectively. As a developer, this is what you will do in your development environment every day.

The recipe includes:

  • Initialize a Git repository or
  • Clone an existing remote repository or
  • Pull latest changes from main remote repository down to local repository if the previous steps have been done initially.
  • Create a new branch.
  • Make changes, stage, and commit.
  • Rebase changes against the main branch (because the main branch is now ahead due to changes made by other devs), this involves stashing before bringing the remote changes from the main branch into the target branch.
  • Manage and resolve conflicts.
  • push new commits to the remote repository.
  • Create a pull request (PR) for the review of changes.
  • If PR is approved, it should be merged to the main remote branch by the project supervisors.
  • Delete branch.

Challenges While learning 😞

I struggled with understanding rebase, it took me the time to go over and over the resources before I could understand it. With more practice as I go, it will become part of me.

What Next? 🚀

I look forward to the next task. Hopefully, it will involve me contributing to an existing repository or maybe I create one from scratch.

I hope this is not too much of a long read, thank you for following.

PS: The images used in this article are not mine, I got them from google image.

👋

Resources

Start blogging about your favorite technologies and get more readers

Join other developers and claim your FAUN account now!

Avatar

Ayobami Oguntolu

Backend Developer, internship

@olaoluwa
👋 I am documenting my backend development journey.
Stats
12

Influence

409

Total Hits

1

Posts

Join FAUN
Start blogging on FAUN

⚡ Grow your network and reach more readers!

Discussed tools