Process to push my Node.js application to a remote GitHub repository?

looper003 asked this question 1 year, 5 months ago
looper003 on Dec 13, 2021

I have a Node.js application that I want to store in a GitHub remote repository?

How do I do this? What are the steps I should follow and in what order?

2 suggested answers
nick on Dec 15, 2021

1. Create a GitHub repository:

Create an empty repository on GitHub.

This is where your code will be pushed.

2. Initialize your Node.js application as a Git repository:

Inside your Node.js application, run this command:

git init

When that command finishes, you should see a .git directory was added to your project. That holds configuration data for your Git repository.

3. Set the remote origin URL:

Inside your application directory, run this command:

git remote add origin

This sets the remote origin URL for your repository. It tells Git where to push your code to.

Make sure you replace the URL in that command with the URL of your GitHub repository.

4. Tell Git what files/directories you want ignored:

There are some files and directories you don't want pushed to GitHub, like the node_modules directory or your .env file.

In the root of your Node.js application, create a new .gitignore file:

touch .gitignore

And add this code to it:

# Logs

# Runtime data

# Directory for instrumented libs generated by jscoverage/JSCover

# Coverage directory used by tools like istanbul

# nyc test coverage

# Grunt intermediate storage (

# node-waf configuration

# Compiled binary addons (

# Dependency directories

# Optional npm cache directory

# Optional REPL history

This tells Git to ignore a plethora of files when it pushes code to GitHub. Feel free to add or remove items from this file.

5. Push code to GitHub:

Now you can push your code to GitHub.

First, stage all your files:

git add .

And create a new commit:

git commit -m "Initial commit."

Push the code to the GitHub remote repository:

git push origin master

You'll be asked to enter your GitHub account credentials.

When the process is complete, go back to GitHub and view the remote repository. Your application's code should be visible there.

0 replies
itsbambi on Dec 15, 2021 · Edited

Some general steps:

  1. Open a terminal and navigate inside your app folder
  2. Run git init to initialize your app as a Git repository
  3. Run git remote add origin github_repo_url command to add a remote repository to your application. This tells Git where to push code to
  4. Stage your files with git add .
  5. Create a new commit with git commit -m "First commit."
  6. Push code to GitHub with git push origin master
  7. View your code on GitHub
0 replies