WDI Fundamentals Unit 2
So far, we've been making changes "locally," editing files and repositories on our computers.
To collaborate with others (and also back up our files just in case our computer goes out of commission), we need to connect our local repository to a "remote" repository.
GitHub is a company, famous for the platform it built to manage Git repositories in the cloud. On GitHub, developers can share their code, comment on it, and review code changes among one another. It's an implementation of the same Git software you installed on your computer, but it also comes with some additional features.
In a lot of ways, GitHub is like Dropbox.
You have a folder in the cloud, your remote repo, which syncs with your computer. You can share this remote repo with others, grant them special permissions, and view different versions of your files.
Below is what the GitHub interface looks like for a repo called
1. Repo Name and Owner: describe who owns the repository, the name of the repo, and whether the repo is public or private.
2. Overview: displays the number of commits, branches, releases, and contributors to a particular repo. Selecting any one of these options will open a detailed view of your selection.
3. Repo File Structure: displays the contents of the repo. Selecting any file or folder will open a detailed view of that file and allow you to edit its content directly.
4. Fork button: allows you to copy a version of this repo (
user/awesome-project) to your own GitHub account.
5. Side Bar: allows you to respond to issues, create pull requests, and change the settings for this repo.
There are many unique GitHub features crammed on this page, but we'll only be using three of them to start.
There are a few different ways to work together on GitHub, and our class is going to use a specific order of operations to do so.
The GA Instructional Team has put together some resources for you in a repository on GitHub. You'll need to retrieve these files and save a copy on your computer using Git.
Eventually, when you've made changes that you'd like to share with our team, you can submit them back to us via our GitHub repo.
Our workflow looks like this:
This workflow consists of the following steps:
Don't worry, we are going to cover this step by step in plenty of detail.
Although it is open source and anyone can read or contribute to its code, Node.js is maintained by a company called Joyent. Not all of these contributors have the ability to edit the original Joyent repo – that wouldn't be very efficient or safe. Someone could accidentally make a change that conflicts with someone else's contributions, causing the code to break. Changes need to be inspected and approved before they can officially be added to the project.
To create a copy of Joyent's repo, you would need to fork it by clicking "Fork" in the upper right-hander corner:
You don't follow these steps just yet. Read this chapter, and then you'll have a chance to try it out yourself in the Unit 2 Assignment.
"Forking" adds a copy of someone else's GitHub repo to your GitHub account.
The forked repo is not perfectly identical, but it includes all the same source files, issues, and commit history.
By forking Joyent's repo, you could have a full working copy of the Node.js source code to play with. When you break something, which you will (everyone does), Node.js won't be affected.
Next, you'll want to be able to edit the code.
To make a local copy of a fork, you'll need to open up the terminal and use a Git command.
You need to navigate to the place where you'd like to store the repo, and then type:
git clone https://url-to-clone
You can find the URL to clone by clicking the green button that says "Clone or Download":
By issuing the clone command, you're asking GitHub via the command line for a copy of your remote repo, and this copy, or clone, ends up in your working directory.
If you're following along in Git Bash in Windows, the commands to copy and paste are a little different than the default Windows copy/paste commands. The command to copy is
control + insert, and the command to paste is
shift + insert.
We covered this in the previous section. As you complete the exercises in the rest of Fundamentals, you'll need to repeat this step frequently.
Once you've committed the changes you've made to the code, your local repo will be different from your remote repo. To update your remote repo on GitHub, you have to push those changes using the Git command
git push origin master.
Don't worry about the
master part just yet.
If you're curious, here's a brief overview:
originis a shortcut for the URL of your default remote repo (in this case, the repo on GitHub). You can have many remotes if you want, but we're only going to work with one in Fundamentals.
masterrefers to the branch on your remote repo where you are currently adding your changes. Again, for now, we're just going to be working on the
Once your changes are pushed to your remote repository on GitHub, you can notify the original repo owner of your changes by submitting a pull request.
A pull request is effectively saying "Hello, maintainer of project X, I made some changes here in my forked copy, and I think they're pretty good. You should add them to your repository." Pull requests are a GitHub feature, so you'll need to head back to the browser to make this happen.
If you ever get stuck working with Git or GitHub, don't worry, you are NOT the first. When you don't understand something, we encourage you to search for an answer via Google or Stack Overflow.
Trust us – you will get to the point where cloning and pushing are like breathing and sleeping.