How To Upload To New Github Repo
Adding a local projection to an empty repository on Github is an like shooting fish in a barrel process. This is a useful workflow for local projects in need of remote versioning. Unfortunately, the instructions offered past Github on an empty repo's URL don't always work out smoothly.
TL;DR – Github's instructions for calculation a local project to an empty repo don't always work out as expected. The post-obit lawmaking will ensure your local projection makes it to the remote repo every fourth dimension. Annotation: this will delete annihilation currently in the remote repo.
git init git add together -A git commit -m 'initial commit' git remote add origin https://github.com/<usename>/<repo-proper name>.git git push -u -f origin master
2022 Update: Github has changed the proper noun of the default co-operative from master
to main
. A previous version of this commodity described pushing things to master
but has been updated to reverberate the change. Read near it here. GIT may not reflect this alter when creating local projects first. To reconfigure one's local GIT software's default co-operative name use the following command:
git config --global init.defaultBranch main
The main
argument represents the new default co-operative proper name (updated from master in well-nigh cases.) This will avoid pushing a second master
branch to new empty Github repos with an empty main
default branch.
Adding A Local Project to an Empty Github Repository
In this article, you'll learn how to speedily initialize a local project folder for versioning via git, create an empty repo on Github, and so push your local project to that repo. The workflow is about identical to that recommended by GitHub with a few notable exceptions we'll cover in some detail.
Pace one: Create a Repository on Github
The first stride in adding a local project folder to a new Github repository is tocreate a new repository! Github makes this process simple and achievable by the following actions:
- Click the drop-downwardly bill of fare from the upper right expanse of the screen near your profile picture icon.
- Select "New repository" every bit your pick
- Enter the repository name and configure options on the resultingCreate a new repository screen.
A local project can be pushed to an existing repository besides—even one that is not empty—simply that process is beyond the scope of this commodity. Permit's see what our newly-minted Github repository looks like.
Step two: Configure Local Project
It should go without maxim you need to have an existing project before attempting to add together something to Github. This requirement can be satisfied either by creating a new project (Option ane) or by pushing an existing projection (Choice ii). The first ane works equally expected but Github'due south instructions for the 2d can cause bug.
Choice 1: Push a Newly-Created Project Folder
Github'southward instructions work perfectly—for those creating a new projection folder without existing version control. This can be accomplished by following the instructions provided by Github. Note: creating the README.dr.
file is optional but the git init
command is essential. Here's the code provided by Github per the new repo screen:
echo "# example" >> README.doctor git init git add README.dr. git commit -grand "first commit" git branch -M primary git remote add together origin https://github.com/<your-username>/<your-repo-name>.git git button -u origin master
Option two: Button an Existing Repository via Command Line
Pushing an existing projection folder where version control is already in identify doesn't ever work when following Github's official instructions. Below are the official Github instructions for adding an existing projection to an empty repository:
git remote add origin https://github.com/<your-username>/<your-repo-proper noun>.git git branch -M main git push button -u origin main
Now, let'southward see what happens when we effort that:
(venv) \path\to\project\Example>git init Initialized empty Git repository in \path\to\project\Example/.git/ (venv) \path\to\projection\Case>git add README.doctor (venv) \path\to\project\Example>git remote add origin https://github.com/alphazwest/instance.git (venv) \path\to\project\Example>git branch -M principal error: refname refs/heads/master not found fatal: Branch rename failed
At this indicate, our new repository is still empty since we weren't able to get to the point where we'd usually push our local project. At least that ways we don't have to nuke our repo to try again. Now, allow's take another arroyo.
Set up: Pushing to Main
Messing effectually with the master chief co-operative direct tin cause trouble. This won't exist an issue in those cases since nosotros're just pushing an existing project to an empty remote repository. At that place's null to overnight, null to merge, and no conflicts to resolve. This can be achieved similarly to the steps taken in Option 2 above, just with a few notable differences:
(venv) \path\to\projection\Instance>git init Initialized empty Git repository in \path\to\project\Case/.git/ (venv) \path\to\projection\Example>repeat "# example" >> README.md (venv) \path\to\project\Example>git add README.md (venv) \path\to\project\Example>git commit -grand "initial commit" [main (root-commit) 2c763fd] initial commit 1 file inverse, 1 insertion(+) create mode 100644 README.md (venv) \path\to\project\Example>git remote add origin https://github.com/<username>/example.git (venv) \path\to\project\Instance>git push -u -f origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (iii/3), 225 bytes | 225.00 KiB/s, washed. Total three (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/<username>/case.git * [new branch] main -> master Branch 'main' set up to track remote branch 'principal' from 'origin'.
Everything worked out nicely this time. So what did we practise differently? There were 2 major differences in our arroyo here:
- We skipped creating a new co-operative via the
branch -Grand main
command. - We specified the
mastermaster branch to push to, using the-f
flag to overwrite any existing content (not completely necessary in this case) and the-u
flag to prepare the remote origin as default (makes push commands easy later on)
Final Thoughts
Version command is i of the hallmarks of responsible software evolution. These powerful tools aren't restricted to professional workflows alone, however. Systems like Git, mercurial, and subversion can be used on projects of all sizes and complexities.
Github makes pushing, pulling, and branching from remote repositories simple. These commands can be issued via command line or, as is the instance with many modern workflows, via integration with IDEs like IntelliJ or Visual Studio.
I often detect myself working on projects locally without having moved versioning and projection files to a Github (or similar) remote repository. The procedure to transfer an existing projection to Github is outlined poorly by Github and often fails. I hope the approach outlined here can help save some commonage Googling for developers everywhere.
Source: https://www.alpharithms.com/adding-existing-project-empty-github-repository-394221/
Posted by: nelsonabrount.blogspot.com
0 Response to "How To Upload To New Github Repo"
Post a Comment