GitHub Oversimplified

abhinaya rajaram
CodeX
Published in
5 min readJan 5, 2023

--

Introduction

GitHub is a website, a cloud-based service that helps users store, manage code, track and control changes. Specifically, Git is a distributed version control system. This means that the entire codebase history is available on every developer’s computer.

The word “Git” implies version control. In other words, it allows developers to keep track of the constant revisions to their code. The word “Hub” here implies a community of like-minded individuals who participate in reviewing, improving, and deriving new ideas from the uploaded code.

Significance of Git

“Maintaining a single source of truth & accelerating release velocity.”

Developers can work together from anywhere in the world, see the full history of the project & can revert to earlier versions of a project. That way, they are able to manage & track changes to code & work on the right version of the source code.

How to Interact with GitHub

There are many ways to interact with GitHub. You can get access via their website at https://github.com or the Git command-line interface (CLI). A rich GitHub integration is provided by the GitHub Pull Requests and Issues extension in VS Code.

To get started with GitHub in VS Code, you will need to install Git, create a GitHub account, and install the GitHub Pull Requests and Issues extension.

Getting started with GitHub Pull Requests and Issues

Once you have installed the GitHub Pull Requests and Issues extension, you will need to sign in, follow the prompts to authenticate with GitHub in the browser and return to VS Code.

If you are not redirected to VS Code, you can add your authorization token manually. You will receive your authorization token in the browser window. You will need to copy the token & switch back to VS Code. Select Signing in to github.com in the Status bar, paste the token, and hit Enter.

Git Hub Terms & Flow Simplified

When working on open-source projects in GitHub, developers like to test out new code changes without affecting the main project.

To do so, a developer first clones the project creates a new branch & implements the code changes in the new branch in the repository locally.

Once finished, the developer requests permission from the project maintainer in Github to implement the changes to the main branch. This is done via a pull request.

After the developer determines that the code is good to go, he/she merges that branch into the master branch. Here is a more detailed sequence of events:

Step 1: Clone →In the programming world, a developer’s project is called a repository and he/she would need to duplicate the project using the clone command.

“git clone type url here”

Step 2: Make your local copy at par with the remote version →Git pull →There could be changes in the remote repository(main) that need to be tracked (on the local side). To do that, we use the git pull command to fetch and download content from a remote repository and immediately update the local repository to match that content.

“git pull”

Step 3: Creating your own space to work →Branching →When developers work off their local copy, they create a descriptively named branch off of the stable master branch. By using branches, several developers are able to work in parallel on the same project simultaneously. We can use the git branch command for creating, listing, and deleting branches.

This one command will do the trick of creating the branch, making it active, and pointing all the GitHub to the branch.

Type in “ git checkout -b branchname”

To double-check if the newly created branch is active →type in “git branch” & you should see the branch highlighted in green with an asterisk sign next to it. This means that this branch is where you are on and that it is active.

Note: Usually developers commit to the branch locally and regularly push their work to the same branch on the server.

Step 4 → Write your code in the branch locally & staging it→A staging step in git allows you to continue making changes to the working directory, and when you decide you want to interact with version control, it allows you to record changes in small commits. The git add command is used to promote or 'stage' changes to the project that will be stored in a commit.

Step 5 → When everything looks good, just commit →Commits are created with the git commit-m “type a message about what this code does"command to capture the state of a project at that point in time. Note that Git Snapshots always commit to the local repository.

Step 6 → Git Push to submit your work to the origin (remote) →The git push command is used to upload local repository content to a remote repository.

Scenario 1: If it is the first time you have created a branch then type

“ git push — set-upstream origin branch name” & see associated changes in github

Scenario 2: If it is not the first time you have created the branch & you are operating and extending code on a branch you created previously then type “git push”. Wait till everything under the Actions tab in Github is complete.

Step 7 →Git Pull request →Making the main branch the same level as the smaller branch→ Pull request lets you tell others about changes you have pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the main branch.

Step 8 →Merge →A merge request is simply a request from a user to merge their code from one branch to another, typically to the master branch.

The best part is that all of these changes are then tracked and can be reverted if need be.

Pushing Changes to Existing PR

If you encounter a situation where have raised a PR, whose checks have failed and the merge is still pending, then you can fix this situation by making additional changes and pushing those changes to the same PR.

To do this, go to your terminal, and make sure you are in the same branch that you had used earlier for pushing the changes. Make your changes, save the file, stage the change, issue a commit and then run “git push origin branch name”.

In summary, we discussed:

  • How to manage projects with Repositories
  • The concept of cloning a project to work on a local copy
  • Pulling the latest version of the project to a local copy
  • Controlling and tracking changes with staging and committing
  • Branching and merging to allow for work on different parts and versions of a project
  • Pushing local updates to the main project

Useful Material

  1. Here is the cheat sheet containing commonly used commands.
  2. An article that I came across while writing this post.
  3. More documentation →https://docs.github.com/en/get-started/using-git/about-git

--

--