How to Upload Project on Existing Repository
Adding a local project to an empty repository on Github is an like shooting fish in a barrel procedure. This is a useful workflow for local projects in need of remote versioning. Unfortunately, the instructions offered by Github on an empty repo's URL don't always piece of work out smoothly.
TL;DR – Github'due south instructions for adding a local project to an empty repo don't always piece of work out as expected. The following code will ensure your local project makes it to the remote repo every time. Annotation: this will delete annihilation currently in the remote repo.
git init git add -A git commit -m 'initial commit' git remote add origin https://github.com/<usename>/<repo-proper name>.git git push -u -f origin master
Adding A Local Project to an Empty Github Repository
In this article, yous'll larn how to speedily initialize a local project binder for versioning via git, create an empty repo on Github, and then push your local project to that repo. The workflow is nearly identical to that recommended by GitHub with a few notable exceptions we'll cover in some detail.
Step 1: Create a Repository on Github
The outset step in adding a local project binder to a new Github repository is tocreate a new repository! Github makes this procedure unproblematic and achievable by the following deportment:
- Click the drop-downwards menu from the upper right surface area of the screen near your profile flick icon.
- Select "New repository" as 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 every bit well—even 1 that is not empty—but that process is beyond the scope of this article. Allow'due south run across what our newly-minted Github repository looks similar.
Stride 2: Configure Local Project
It should become without proverb you need to accept an existing project before attempting to add something to Github. This requirement tin can be satisfied either by creating a new projection (Option 1) or past pushing an existing project (Option 2). The get-go one works as expected but Github's instructions for the 2nd can cause issues.
Option 1: Push a Newly-Created Project Folder
Github's instructions work perfectly—for those creating a new project folder without existing version control. This tin can be achieved past following the instructions provided by Github. Notation: creating the README.md
file is optional merely the git init
command is essential. Here'south the code provided by Github per the new repo screen:
echo "# example" >> README.md git init git add together README.md git commit -m "kickoff commit" git co-operative -1000 main git remote add together origin https://github.com/<your-username>/<your-repo-name>.git git push -u origin primary
Option 2: Push button an Existing Repository via Control Line
Pushing an existing project binder where version control is already in place doesn't e'er work when post-obit Github's official instructions. Beneath are the official Github instructions for calculation an existing project to an empty repository:
git remote add origin https://github.com/<your-username>/<your-repo-name>.git git branch -1000 main git push -u origin main
At present, let'south see what happens when we try that:
(venv) \path\to\project\Case>git init Initialized empty Git repository in \path\to\projection\Example/.git/ (venv) \path\to\projection\Example>git add README.dr. (venv) \path\to\projection\Case>git remote add together origin https://github.com/alphazwest/example.git (venv) \path\to\projection\Example>git branch -M main error: refname refs/heads/primary not plant fatal: Branch rename failed
At this bespeak, our new repository is still empty since we weren't able to get to the betoken where we'd normally push our local project. At least that means we don't take to nuke our repo to try again. Now, let's accept another approach.
Fix: Pushing to Main
Messing effectually with the master branch directly 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. There's zippo to overnight, nothing to merge, and no conflicts to resolve. This can be achieved similarly to the steps taken in Selection 2 above, simply with a few notable differences:
(venv) \path\to\projection\Example>git init Initialized empty Git repository in \path\to\projection\Example/.git/ (venv) \path\to\project\Case>echo "# example" >> README.doctor (venv) \path\to\project\Example>git add together README.md (venv) \path\to\project\Instance>git commit -yard "initial commit" [master (root-commit) 2c763fd] initial commit ane file changed, 1 insertion(+) create mode 100644 README.md (venv) \path\to\project\Case>git remote add together origin https://github.com/<username>/example.git (venv) \path\to\project\Case>git push -u -f origin principal Enumerating objects: 3, done. Counting objects: 100% (3/iii), done. Writing objects: 100% (3/three), 225 bytes | 225.00 KiB/due south, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/<username>/instance.git * [new co-operative] master -> master Branch 'principal' prepare up to track remote branch 'master' from 'origin'.
Everything worked out nicely this fourth dimension. Then what did we do differently? There were two major differences in our approach here:
- We skipped creating a new branch via the
branch -M main
command. - We specified the master branch to push to, using the
-f
flag to overwrite whatsoever existing content (not completely necessary in this case) and the-u
flag to set the remote origin as default (makes push commands easy subsequently)
Terminal Thoughts
Version control is i of the hallmarks of responsible software evolution. These powerful tools aren't restricted to professional workflows alone, withal. Systems similar 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 case 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 process to transfer an existing projection to Github is outlined poorly by Github and oft fails. I hope the approach outlined here tin assistance salvage some commonage Googling for developers everywhere.
marshallholed1953.blogspot.com
Source: https://www.alpharithms.com/adding-existing-project-empty-github-repository-394221/
Post a Comment for "How to Upload Project on Existing Repository"