Javascript required
Skip to content Skip to sidebar Skip to footer

How to Upload Your Project to Existing Repository Using Git Bash

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

It'south a convenient and mostly worry-free method for backing upwards all your code repos. It also allows yous to very nicely navigate and view your code on the spider web. GitHub takes this even farther past 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 gratuitous GitHub Account
  2. git installed on your local machine

Step ane: Create a new GitHub Repo

Sign in to GitHub and create a new empty repo folio. You can choose to either initialize a README or not. It doesn't really matter because we're just going to override everything in this remote repository anyways.

Create new GitHub Repo

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

Step 2: Initialize Git in the project binder

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

Initialize the Git Repo

Brand certain yous are in the root directory of the project you want to push button to GitHub and run:

Annotation: if y'all already have an initialized Git repository, you can skip this command

                      
  1. git init

This step creates a hidden .git directory in your project folder which the git software recognizes and uses to shop all the metadata and version history for the project.

Add together 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 -g 'Added my project'

The git commit command creates a new commit with all files that have been "added". the -m 'Added my project' is the message that will be included aslope the commit, used for future reference to empathize the commit.

Add new remote origin (in this case, GitHub)

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

Note: Don't forget to supercede the highlighted bits higher up with your username and repo proper name.

In git, a "remote" refers to a remote version of the same repository, which is typically on a server somewhere (in this instance GitHub.) "origin" is the default proper name git gives to a remote server (you lot can have multiple remotes) so git remote add together origin is instructing git to add together 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 really necessary.

The -u flag sets the remote origin as the default. This lets you lot later easily merely do git push and git pull without having to specifying an origin since we always want GitHub in this case.

All together

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

Conclusion

Now you are all set to rail your code changes remotely in GitHub! Equally a side by side step here's a complete guide to how to use git

In one case you start collaborating with others on the projection, yous'll want to know how to create a pull request.

ribushhigend.blogspot.com

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