Source Control with Git

Sheniell Sinclair
6 min readAug 7, 2022

--

In this article I’ll provide guidance on how to edit and change code from a public git repository, and reupload the code for my team to assess before it is put into production.

Things I’ll need: A Cloud Guru account for cloud server environment, git utility, github.com account, and vim text editor. But before we get started…

What is Git?

According to, What is Git: Features, Command and Workflow in Git [Updated] (simplilearn.com), “Git is a free open-source version control system used to handle small to very large projects efficiently. Git is used to track changes in the source code, enabling multiple developers to work together on non-linear development. Linus Torvalds created Git in 2005 for the development of the Linux kernel.” I’ll be using this utility in my Linux cloud server environment to edit and make changes to my team’s production source code.

What is GitHub?

GitHub is basically social network for programmers to share source code. Companies and organizations primarily use GitHub to facilitate projects and collaboration among programmers. GitHub houses the source code that I will need to copy back to my local machine and edit for my team to review.

What is Vim?

Vim is an open-source UNIX based text editor. This utility is run inside a terminal window making it extremely fast. It can be operated with just a keyboard so there is no need for a mouse or scratch pad. I’ll be using this utility to edit the code file.

[Prior to starting, have a github.com account already created]

LET’S GET STARTED:

Phase 1: In order to start using git we must install and configure the utility.

Step 1: Start by logging into the Linux (CentOS7) virtual cloud environment located in A Cloud Guru via port 22. (Check out how to set up a virtual server in ACG in my pervious publication Testing with Ubuntu 18.04 +NGINX. ) {ssh (user)@(publicIP)}

Format: ssh (user)@(virtual cloud public IP address)

Step 2: To install Git utility for RedHat based distributions use the {yum} command. This requires superuser permissions as well (NOTE: Ensure all packages on the server are up to date). {sudo yum install git}

Git package install command
Installation verification

Step 3: Configure the git utility to reflect the user making changes in the repository and core editing tool to be used. {git config - -global user.email “email for associated git account”}, {git config - -global user.name “username for git account”}, {git config - -global core.editor “path to editor”}, {git config - -list}

Phase 2: Head over to GitHub.com to complete this portion of the project. Fork and clone the repository for the code that needs editing.

Step 1: Login to GitHub.com, then go to the LevelUpInTech Team public repo page (LevelUpInTech/LevelUpTeam: Level Up In Tech Repo (github.com) and fork the repository.

Step 2: Next hit the green “Code” button and copy the link. (Notice: at the top left it displays (username/name of forked repo), and directly under it shows the source of the repo).

Step 3: Head back to the Command line to clone the remote repository. {git clone (https link copied from code button)}.

Step 4: Switch to the cloned repository now existing locally and take a look at all the files. {cd LevelUpTeam} {ls -al}.

Phase 3: Create a separate branch to edit the README.md.LUIT file.

“Why branch?” The reason we create a separate branch is to maintain the integrity of the original repository. Branching allows developers to work on segments of a project without affecting code in the main branch. This ensures version control and allows revision back to old code if branched work is not up to par.

Step 1: Let’s take a look at the main (master) branch {git status}

Status of main branch

Step 2: Let’s create a branch to work in. {git chechout -b LevelUpProject}

Step 3: Now we must edit the file README.md.LUIT. Because we set vim as our editor, we must use command {vim README.md.LUIT}.

Step 4: Once in the file make the necessary changes according to the directions. You must hit the [i] key to start inserting text into the editor. You can navigate the editor by pressing [esc] then using [h]left, [k]up, [j]down, [l]right.

Step 5: Now we’ll get rid of all the instructions with a vim search and delete pattern. press [esc] then type. {: g/<*>/d}, because the instructions are housed in “<>” signs. The “*” expresses any character or size of text within the greater than and less than signs.

Step 6: write and quit the vim editor to save your work then quit the editor {:wq}

Phase 4: Commit changes to local repo and push back to remote repo.

Step 1: Check git status on current branch. {git status}

Step 2: Add the file to the staging area {git add README.md.LUIT}

Step 3: Commit the changes in the staging area. {git commit -m “comment”}

Step 4: Merge the branches back together so that new changes are reflected in the local repository. {git checkout main} (must switch to branch you want to merge into.)

Move to main branch

Step 5: Now we must push the changes back to our remote repository. {git push (link to remote repo)} (NOTE: This will fail if you have not created a Personal Access Token.)

Let’s head back to GitHub: Got to [Settings]> [Developer Settings]> [Personal Access Tokens]> [Generate new token]. You’ll be prompted to put in your password then choose configuration settings for the token. Copy the generated Token.

Retry… (Input Personal Access Token in password field)

Successful Push
Successful update of remote repo
Details of commit changes

LAST PHASE: Send a push request to the Level Up Team public repository.

Step 1: On the same exact page where details can be viewed of changes made, Click the “Create pull request” button

NOW WE’RE ALL DONE!!

Thank you for reading

Connect with me on LinkedIn:

www.linkedin.com/in/sheniell-sinclair

--

--

Sheniell Sinclair

DevOps/Cloud Engineer. Here I’ll document my learning and projects in the Cloud. www.linkedin.com/in/sheniell-sinclair