Tutorial

How To Fork, Clone & Push Changes Using Git and Github

Git

While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or edited it to ensure you have an error-free learning experience. It's on our list, and we're working on it! You can help us out by using the "report an issue" button at the bottom of the tutorial.

Introduction

Github is an excellent resource for finding useful code. In order to contribute changes back to a project, you’ll need to make a local copy and then upload your changes. In this tutorial, you’ll fork and clone an existing repo, and then make changes to your local copy of the repo and push them back to Github.

Fork and Clone

Go to the Skeletonwebsite repository on Github and click on Fork.

Fork a website on Github

Fork will create a copy of the repository in your Github account so that you can make changes to the project.

Go to your own Github repository and you will see a repository named skeletonwebsite.

Click into this repository and we will now make a local copy of it on your machine by hitting the clone button.

Copy the Https URL.

Open your terminal or git bash window.

Move to the location on your computer where you want to create a copy of this project.

Run the following command:

git clone https://github.com/userid/skeletonwebsite.git

Substitute your Github username for userid.

You now have a local copy on your computer.

The folder on your computer will have the same name as the remote repository on Github, skeletonwebsite

cd into skeletonwebsite.

Run thegit initcommand.

The git folder after running git init

After running git init you should see a hidden git folder in your skeletonwebsite directory. If you don’t see it, change the settings on your computer to show hidden files and directories.

Now run git status to see the current status of your local repository. This will show if you have any commits that are staged or committed.

Open up theindex.html file in your code editor.

Add a heading or a paragraph.

Now run git status.

You should see that there are changes not staged to be committed with theindex.html file in red.

Changes not staged for committing

We will now add this change by running git add index.html. If you want to add multiple files at once then you can run git add . Run git status

Changes staged for committing

Changes have now been staged and are ready to be committed.

Now we can run git commit to commit these changes.

Use the-m flag to add a commit message.

Remember to describe the specific change you made in the git commit message.

Commit message

Run git status again to check that everything is up to date.
Checking git status

This message shows everything is up to date.

We can now push our code to our repository on Github.

Before we do this, run git remote -vto see what remote repository on Github our local repository is connected to.
Checking the remote repository

Push Changes

Run git push origin master to push our changes to this repository.

Changes pushed to Github

Check that your remote repository has updated on Github

Updated remote repository

Conclusion

In this tutorial, you have successfully:

  1. Forked a repo.
  2. Cloned it to create a local repo on your computer.
  3. Made a change to the index.html file.
  4. Staged this change.
  5. Committed this change.
  6. Confirmed what remote repo your local repo is connected to.
  7. Successfully pushed your code to your forked repo on Github.
Creative Commons License