How to Create a Repository in Github and Upload Files
GitHub is just a deject-hosted Git management tool. Git is distributed version command, meaning the entire repo and history lives wherever you put it. People tend utilise GitHub though in their business or development workflow as a managed hosting solution for backups of their repositories.
Information technology's a convenient and mostly worry-complimentary method for bankroll upwards all your code repos. It also allows you to very nicely navigate and view your lawmaking on the web. GitHub takes this even further past letting you connect with coworkers, friends, organizations, and more.
Prerequisites:
To initialize the repo and push it to GitHub you'll need:
- A costless GitHub Account
-
git
installed on your local motorcar
Footstep one: Create a new GitHub Repo
Sign in to GitHub and create a new empty repo page. You can choose to either initialize a README or not. It doesn't really affair because we're simply going to override everything in this remote repository anyways.
Through the rest of this tutorial we'll presume your GitHub username is sammy
and the repo y'all created is named my-new-project
(So you lot'll need to swap those out with your actual username and repo name when copy/pasting commands)
Step 2: Initialize Git in the project folder
From your terminal, run the post-obit commands subsequently navigating to folder you would similar to add together:
Initialize the Git Repo
Make sure you are in the root directory of the project you want to button to GitHub and run:
Notation: if y'all already accept an initialized Git repository, you tin skip this control
- git init
This step creates a hidden .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
- git add -A
The git add together
command is used to tell git which files to include in a commit, and the -A
argument ways "include all".
Commit Added Files
- git commit -k 'Added my project'
The git commit
control creates a new commit with all files that have been "added". the -m 'Added my project'
is the bulletin that will exist included alongside the commit, used for future reference to empathise the commit.
Add new remote origin (in this case, GitHub)
- git remote add origin git@github.com:sammy/my-new-project.git
Note: 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 same repository, which is typically on a server somewhere (in this case GitHub.) "origin" is the default name git gives to a remote server (you tin accept multiple remotes) and then git remote add origin
is instructing git to add together the URL of the default remote server for this repo.
Push to GitHub
- git push button -u -f origin master
With this, there are a few things to note. The -f
flag stands for forcefulness. This will automatically overwrite everything in the remote directory. We're only using it here to overwrite the README that GitHub automatically initialized. If you lot skipped that, the -f
flag isn't actually necessary.
The -u
flag sets the remote origin every bit the default. This lets you subsequently easily simply practise git push
and git pull
without having to specifying an origin since nosotros always want GitHub in this case.
All together
- git init
- git add -A
- git commit -thousand 'Added my project'
- git remote add origin git@github.com:sammy/my-new-project.git
- git push -u -f origin principal
Conclusion
At present y'all are all set to rails your code changes remotely in GitHub! Equally a side by side step here'southward a complete guide to how to apply git
Once you showtime collaborating with others on the projection, you'll want to know how to create a pull asking.
Source: https://www.digitalocean.com/community/tutorials/how-to-push-an-existing-project-to-github