How To Fork, Clone & Push Changes Using Git and Github
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.
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 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.
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.
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 the
index.html file in your code editor.
Add a heading or a paragraph.
You should see that there are changes not staged to be committed with the
index.html file in red.
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
Changes have now been staged and are ready to be committed.
Now we can run
git commit to commit these changes.
-m flag to add a commit message.
Remember to describe the specific change you made in the git commit message.
git status again to check that everything is up to date.
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.
git push origin master to push our changes to this repository.
Check that your remote repository has updated on Github
In this tutorial, you have successfully:
- Forked a repo.
- Cloned it to create a local repo on your computer.
- Made a change to the index.html file.
- Staged this change.
- Committed this change.
- Confirmed what remote repo your local repo is connected to.
- Successfully pushed your code to your forked repo on Github.