Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 833 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Pushing to GitHub

2:34 JavaScript lesson by

Once you've written some code and you feel good about it, it's time to commit that code and push it up to your GitHub repository for storage and collaboration.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

Once you've written some code and you feel good about it, it's time to commit that code and push it up to your GitHub repository for storage and collaboration.

Now that we have some work done locally, let's go ahead and commit this up to GitHub so that we can save our work. If we type in "git-status," we're going to have a couple of things in here.

One of those is this nodemodules directory. It's not advisable to commit your nodemodules directory for several reasons. One of these is collaborating with other users. Another is messing up your Git history with a lot of unnecessary changes that you may or may not actually want in your Git history.

We're going to use NPM to make sure that we have our dependencies properly locally, and we will gitignore our node-modules. Let's create a new file here, called .gitignore, and this will tell Git to ignore certain directories or files in our project.

We can say "node-modules" and, now, if we say "git-status," that's no longer there. Now, we have this .gitignore file, which is just fine. What we need to do here, just as it illustrates for us, is we need to add these untracked files.

We'll say "git-add." We'll just say -A to add everything. Now, if we say "git-status," it says we have a few new files, and we can commit these to our repository.

We'll simply say "git-commit," and, then, we'll add a message of "adding the library." Now, if we say "git-status," we have one commit ahead of our origin master. We can git-push, and that will update our origin master.

Now, if we go to our Star Wars Names repository, we have a source directory, a git-ignore, and a package JSON, everything that we need for our library to actually be published and used by consumers. However, we don't want to force people to go to our repository, go to the source directory, open up the index, copy this.

This isn't something that we want people to do. We want them to be able to install our library from NPM. Next, we're going to publish this library to NPM.

In review, all that we needed to do was create a .gitignore file that specified node_modules as an ignored directory. Then, we said, "git-add" to add the untracked files, the new files that we created. Then we have a git-commit to commit these files to our repository. Finally, we pushed these up to the GitHub repository.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?