How to Upload on Github via Git
GitHub is only a cloud-hosted Git management tool. Git is distributed version command, meaning the entire repo and history lives wherever you put it. People tend apply GitHub though in their business or development workflow every bit a managed hosting solution for backups of their repositories.
It's a convenient and mostly worry-free method for bankroll up all your code repos. It also allows you lot to very nicely navigate and view your code on the web. GitHub takes this even further by letting you connect with coworkers, friends, organizations, and more.
Prerequisites:
To initialize the repo and push button it to GitHub you'll need:
- A costless GitHub Account
-
gitinstalled on your local machine
Step one: Create a new GitHub Repo
Sign in to GitHub and create a new empty repo page. Y'all 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.
Through the balance 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 swap those out with your actual username and repo name when re-create/pasting commands)
Step 2: Initialize Git in the project binder
From your concluding, run the following commands after navigating to folder you would like to add:
Initialize the Git Repo
Make sure yous are in the root directory of the projection y'all want to push to GitHub and run:
Note: if you already have an initialized Git repository, you lot tin can skip this command
- git init
This step creates a hidden .git directory in your project folder which the git software recognizes and uses to store all the metadata and version history for the project.
Add the files to Git index
- git add -A
The git add control is used to tell git which files to include in a commit, and the -A argument ways "include all".
Commit Added Files
- git commit -g 'Added my project'
The git commit command creates a new commit with all files that take been "added". the -g 'Added my project' is the message that will be included aslope the commit, used for future reference to understand 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 $.25 higher up 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 instance GitHub.) "origin" is the default proper name git gives to a remote server (you tin 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 button to GitHub
- git push -u -f origin main
With this, there are a few things to note. 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 yous later hands just exercise git push and git pull without having to specifying an origin since we always want GitHub in this instance.
All together
- git init
- git add -A
- git commit -m 'Added my project'
- git remote add origin git@github.com:sammy/my-new-project.git
- git button -u -f origin chief
Decision
Now you are all set to runway your code changes remotely in GitHub! As a next step here's a complete guide to how to use git
Once you lot start collaborating with others on the projection, you'll want to know how to create a pull request.
Source: https://www.digitalocean.com/community/tutorials/how-to-push-an-existing-project-to-github
0 Response to "How to Upload on Github via Git"
ارسال یک نظر