Use Git to Make Changes to Code

Hands-On Lab


Photo of Will Boyd

Will Boyd

DevOps Team Lead in Content





Source Control Management (SCM) is an essential component of any DevOps pipeline. Git is the leading source control tool, and an understanding of its functionality is useful in a variety of roles. This activity will guide you through the basics of installing git and using a git workflow. After installing and configuring git, you will make a code change, commit it, push it to a remote git repository, and merge it using a pull request.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Use Git to Make Changes to Code

In this lab, we will make a change to the train-schedule app. Instead of the app's main page header reading "Train Schedule," the customer wants it to read “Find your train!” This text can be found in the project file views/index.jade on GitHub.

You can find the file here.

Install Git

To push a change to the code, you will need to:

Install git:

sudo yum -y install git    

Configure the name and email address associated with git:

git config --global "<YOUR NAME>"
git config --global "<YOUR EMAIL>"

Create an SSH key, using the default settings:

ssh-keygen -t rsa -b 4096

Display the contents of our new public key (be sure to copy the key to your clipboard):

cat /home/cloud_user/.ssh/

Log in to GitHub, navigate to Settings, click on SSH and GPG keys, and click on New SSH Key. Paste your public key information into this field and then click Add SSH key.

Create a Fork

Create a personal fork of the sample repository

Clone your personal fork from GitHub.

  • Click the green Clone or download button and copy the string that is displayed
  • In your terminal, run the following command:

    cd ~/
    git clone
    cd cicd-pipeline-train-schedule-git/

Create a feature branch to contain the change:

git checkout -b myBranch

Change the header text in views/index.jade from “Train Schedule” to “Find your train!”:

vim views/index.jade

Add the change in views/index.jade to the next commit:

git add .

Commit the change:

git commit -m "<UNIQUE MESSAGE>"

Push the Commit

Push the change to the remote SCM repository:

git config --global push.default simple
git push --set-upstream origin myBranch

Create a pull request to merge the feature branch into the master branch:

  • On the GitHub fork page, click Branches, locate myBranch under Your branches, and click New pull request.
  • In the top-left of the new pull request, change the base fork dropdown menu to your personal fork.
  • Click Create pull request

Merge the pull request

  • After a few moments, click the Merge pull request button
  • Click Confirm merge

The change is pushed.


We have installed Git, created a fork of a file, edited to fulfill our needs, and have pushed the change. Congratulations on completing this lab!