Intro to Git and GitHub Part 2: Publishing, cloning, and forking.

This is a continuation of a tutorial blog series to learn the basics of Git, using GitHub and the GitHub client.

To start from the beginning, go here.

Publish a new repository

Time to put your project online!

GitHub makes it easy to share your code with others online!

To publish your local repository, click the “Publish Repository” button in the upper right hand corner.

Publish01GitHub will give you some choices. If you want to release your source code for everyone to see, it’s free.

Publish02Click publish and in a moment your code will be online!

Once your project is linked to an online repository, the publish button will change to a “Sync” button.

Publish03If you want to make sure you have the latest code from the web, click the button to see if you need to download any changes.

Push changes

After you’ve made a new commit, the Sync button will show that your local repository is ahead of the current online one.

Publish04To “Push” these changes to the server, just click the sync button!

Now you can reach the latest code for your projects from any computer with an internet connection.

Clone an existing repository

To download an existing repository to your computer, you have to “Clone” it.

GitHub’s client makes it easy to clone any repository tied to your GitHub account. Click the new repository button, and hit the “Clone” tab.

Publish05Here you’ll see a list of all the repositories tied to my GitHub account. Highlighted is the MyFirstRepo repository I just uploaded.

You can get to other repositories by going to GitHub.com. On the side of every public project page on GitHub, you’ll see these two buttons:

Publish06If you just want to download the files, you can go for the zip. But if you would like to be able to look at past commits, and commit your own changes, click the “Clone in Desktop” button and GitHub will automatically request to open your GitHub client.

Choice a place to save the files in, and now you have your own copy of that repository on your local machine!

Fork an existing repository

“Forking” is similar to cloning, but GitHub automatically links your new cloned repository to the original repository from which it came from.

Using your web browser on GitHub‘s website, there is a “Fork” button on the top right of project pages.

Publish07Forking a project adds a new repo to your account, which you can then clone to your local machine in GitHub’s client. You can make whatever changes you would like to your version of the repository, and it won’t affect the original.

Why would you want to do this? Because now you work on your own code and modifications without worrying about messing up someone else’s code (or their code messing with yours). Then when you’re ready, you can make a pull request to merge those changes back in.

Pull requests

Let’s say you want to work on an open source project. You decide to add a new feature to make the project even better.

You could clone it and work on your own new repo, which you may or may not share with others. Instead, you should work on a fork of the original project.

Then when you’ve finished making your changes and want to push them back into the original project for others to use, you can make a new “Pull” request. GitHub has a system for this built right into the website.

You can add documentation of exactly what you added and why, and the repository owner can check all the changes before making them officially part of the original repository.

That’s how you can contribute to the projects of others, and that is one of the basis of how open sourced software is built! Now you too can be an open source developer.

End of Part 2

Click here to return to the main blog post. Part 3 will be posted on Monday.

-Tobiah

3 thoughts on “Intro to Git and GitHub Part 2: Publishing, cloning, and forking.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>