Photo Credit: RTask

Using Git and GitHub to fork, clone and push repository

Boman Avong
4 min readJun 28, 2021

--

Git is the most widely used modern version control system in the world today while GitHub is a code hosting platform for version control and collaboration.

Objectives:

  1. Fork the “LevelUpInTech/LevelUpTeam” Repo
  2. Clone the forked repo to your local server environment
  3. Using Vim, create a change in the file that is in the repo directory
  4. Save the file and add to your local repo, then commit the file
  5. Push the file back to your own GitHub repo
  6. Send a pull request to merge with Level Up In Tech production repo

Prerequisites:

  1. CentOS or Ubuntu
  2. GitHub account

Project 2 Steps:

  1. Fork the “Level Up In Tech/LevelUpTeam” Repo

a. Debian Based Install: Use apt-get-install git to install git on your system from your distribution's repositories. Verify version of git by running git — version. Prior to installing git, ensure that you run an update by using the command sudo apt-get update.

Fig 1. Debian Based Git Install

b. Customizing Git using Git Configuration: Specify Git configuration settings with the git config command. This step will allow you set user name, email and type of editor by running the following commands:

git config — global user.name hhuurr

git config — global user.email hhuurr@gmail.com

git config — global core.editor vim

Run git config — list to view configured information.

Fig 2. Configuring Git

c. Fork the “LevelUpInTech” Repo: To fork the LevelUpInTech/LevelUpTeam repo, log in to GitHub and search for “LevelUpTeam”. On the top right corner click on “Fork”. This creates a copy of the original repository on the GitHub account.

Fig 3. Forking main repo

2. Clone the forked repo into your local environment

a. Cloning the forked repo is executed by running the command git clone https://github.com/bizzle09/LevelUpTeam.git. The result is copied to the local machine with the help of git.

Fig 4. Cloning main repo

3. Using Vim, create a change in the file that is in the repo directory

a. Change directory by executing cd LevelUpTeam. List content of the directory by running the ls -l command to locate the linux.sh file. From the command line, use the vim linux.sh to view the contents of the file. Click i on the keyboard to switch to insert mode on vim. Make changes and hit escape to return to normal mode. Save file by typing :wq! and hit enter.

Fig 4. Modifying test file

4. Save the file and add to your local repo, then commit the file

a. To add the file to the local repo, use git add linux.sh. To verify, use the git status to ensure the modified file is available. Running the git commit -m “Add existing file to repo” will commit the tracked changes and get the file ready to be pushed to a remote repository. Again if we do a git status we will see that the file is ready to be pushed. Notice how our branch is ahead of “origin/main” by 1 commit. This message is telling us that we have made some changes locally, and we are now ahead of the origin server. In a sense, this message is a reminder that we need to push changes back to the origin server.

Fig 5&6. Add and commit file in Git

5. Push the file back to your own GitHub repo

a. The git push command is used to upload local repository content to a remote repository. To complete this step we will execute the command git push origin main where main is the branch. The system will request for username and password and output the status of complete git status. Again, verify by running the git status. Notice how our branch is up to date with “origin/main” because we have now executed the push command.

Fig 7. Push request to origin main

6. Send a pull request to merge with Level Up In Tech production repo

a. Pull requests let you tell others about changes you’ve pushed to a branch in a repository on GitHub. Open GitHub and click on the repository and then request for a pull, complete request by adding necessary comments. Changes for approval will be highlighted in green.

Fig 8. Pull request

--

--