Skip to content Skip to sidebar Skip to footer

How to Upload Local Directory to Github

GitHub is simply a cloud-hosted Git management tool. Git is distributed version control, meaning the entire repo and history lives wherever y'all put it. People tend use GitHub though in their business or evolution workflow as a managed hosting solution for backups of their repositories.

It's a convenient and mostly worry-free method for backing up all your code repos. It also allows you to very nicely navigate and view your code on the web. GitHub takes this fifty-fifty farther by letting you connect with coworkers, friends, organizations, and more.

Prerequisites:

To initialize the repo and push information technology to GitHub you'll need:

  1. A gratis GitHub Account
  2. git installed on your local automobile

Step 1: Create a new GitHub Repo

Sign in to GitHub and create a new empty repo page. You can cull to either initialize a README or not. It doesn't actually affair because nosotros're simply going to override everything in this remote repository anyways.

Create new GitHub Repo

Through the residuum of this tutorial we'll presume your GitHub username is sammy and the repo you lot created is named my-new-project (So you'll demand to swap those out with your actual username and repo name when re-create/pasting commands)

Step ii: Initialize Git in the projection folder

From your terminal, run the following commands after navigating to folder you would like to add:

Initialize the Git Repo

Make sure you lot are in the root directory of the project you lot desire to push to GitHub and run:

Notation: if you lot already take an initialized Git repository, you can skip this command

                      
  1. git init

This step creates a subconscious .git directory in your projection folder which the git software recognizes and uses to store all the metadata and version history for the projection.

Add the files to Git index

                      
  1. git add -A

The git add command is used to tell git which files to include in a commit, and the -A argument means "include all".

Commit Added Files

                      
  1. git commit -m 'Added my projection'

The git commit control creates a new commit with all files that take been "added". the -one thousand 'Added my project' is the bulletin that volition exist included alongside the commit, used for future reference to understand the commit.

Add new remote origin (in this example, GitHub)

                      
  1. git remote add origin git@github.com:sammy/my-new-project.git

Notation: Don't forget to replace the highlighted bits above with your username and repo name.

In git, a "remote" refers to a remote version of the aforementioned repository, which is typically on a server somewhere (in this case GitHub.) "origin" is the default name git gives to a remote server (y'all can have multiple remotes) so git remote add origin is instructing git to add the URL of the default remote server for this repo.

Push to GitHub

                      
  1. git push -u -f origin main

With this, there are a few things to notation. The -f flag stands for force. This will automatically overwrite everything in the remote directory. We're only using it here to overwrite the README that GitHub automatically initialized. If yous skipped that, the -f flag isn't actually necessary.

The -u flag sets the remote origin as the default. This lets you afterward easily just practice git push and git pull without having to specifying an origin since we e'er want GitHub in this case.

All together

                      
  1. git init
  2. git add together -A
  3. git commit -m 'Added my project'
  4. git remote add origin git@github.com:sammy/my-new-project.git
  5. git push -u -f origin master

Determination

Now y'all are all fix to track your code changes remotely in GitHub! As a next step here'south a consummate guide to how to utilise git

Once you lot kickoff collaborating with others on the project, you'll want to know how to create a pull request.

whitegress1952.blogspot.com

Source: https://www.digitalocean.com/community/tutorials/how-to-push-an-existing-project-to-github

Post a Comment for "How to Upload Local Directory to Github"