How to Upload My Existing Projects on Mac to Github

Calculation a local project to an empty repository on Github is an easy procedure. This is a useful workflow for local projects in need of remote versioning. Unfortunately, the instructions offered by Github on an empty repo'southward URL don't ever work out smoothly.

TL;DR – Github'south instructions for adding a local project to an empty repo don't always work out as expected. The following code will ensure your local project makes it to the remote repo every time. Note: this will delete anything currently in the remote repo.

git init git add -A git commit -m 'initial commit' git remote add together 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, you'll learn how to quickly initialize a local project folder for versioning via git, create an empty repo on Github, so button your local project to that repo. The workflow is nearly identical to that recommended past GitHub with a few notable exceptions we'll embrace in some particular.

Step 1: Create a Repository on Github

step1 create a new repo
Select the create new repository selection from the drop-down menu about your profile icon

The first step in adding a local project folder to a new Github repository is tocreate a new repository! Github makes this procedure simple and doable past the post-obit deportment:

  1. Click the drop-downwards menu from the upper right area of the screen nigh your profile moving picture icon.
  2. Select "New repository" as your selection
  3. Enter the repository name and configure options on the resultingCreate a new repository screen.

A local projection can be pushed to an existing repository likewise—fifty-fifty one that is not empty—but that process is across the scope of this article. Let's run across what our newly-minted Github repository looks like.

Step ii: Configure Local Project

It should go without saying you need to have an existing project before attempting to add something to Github. This requirement can be satisfied either by creating a new project (Option 1) or past pushing an existing project (Choice 2). The first i works equally expected but Github's instructions for the second can cause problems.

Pick 1: Push a Newly-Created Project Folder

step2 option1 push new project to githhub
Creating a new project and following Github's instructions works out every bit expected. (click to overstate)

Github's instructions work perfectly—for those creating a new projection folder without existing version control. This can be accomplished by following the instructions provided past Github. Note: creating the README.md file is optional but the git init command is essential. Here'southward the code provided by Github per the new repo screen:

echo "# instance" >> README.physician git init git add together README.md git commit -m "first commit" git branch -Thousand main git remote add origin https://github.com/<your-username>/<your-repo-name>.git git push button -u origin main

Pick 2: Button an Existing Repository via Command Line

option 2 add existing project to repo
Github'southward instructions for pushing an existing projection to an empty repository fall brusque and throw an mistake. (click to overstate)

Pushing an existing project binder where version control is already in place doesn't always piece of work when following Github's official instructions. Below are the official Github instructions for adding an existing project to an empty repository:

git remote add origin https://github.com/<your-username>/<your-repo-name>.git git branch -M principal git push -u origin main

Now, let's see what happens when we try that:

(venv) \path\to\project\Example>git init Initialized empty Git repository in \path\to\project\Example/.git/  (venv) \path\to\project\Example>git add together README.dr.  (venv) \path\to\project\Case>git remote add origin https://github.com/alphazwest/instance.git  (venv) \path\to\project\Example>git co-operative -M principal  error: refname refs/heads/chief not found fatal: Co-operative rename failed          

At this signal, our new repository is withal empty since we weren't able to get to the point where nosotros'd normally button our local project. At to the lowest degree that means we don't have to nuke our repo to endeavour over again. At present, let's take another approach.

Fix: Pushing to Master

workaround push to master
Specifying the master branch equally the remote origin and force pushing will get the job done. (click to enlarge)

Messing around with the master branch direct tin crusade trouble. This won't be an issue in those cases since we're simply pushing an existing project to an empty remote repository. There'southward nothing to overnight, zip to merge, and no conflicts to resolve. This can be achieved similarly to the steps taken in Pick two above, but with a few notable differences:

(venv) \path\to\project\Instance>git init Initialized empty Git repository in \path\to\project\Example/.git/  (venv) \path\to\project\Example>echo "# instance" >> README.doc  (venv) \path\to\project\Example>git add README.md  (venv) \path\to\projection\Example>git commit -yard "initial commit" [master (root-commit) 2c763fd] initial commit  1 file inverse, 1 insertion(+)  create manner 100644 README.md  (venv) \path\to\project\Case>git remote add origin https://github.com/<username>/example.git  (venv) \path\to\project\Example>git push -u -f origin master Enumerating objects: 3, done. Counting objects: 100% (three/3), washed. Writing objects: 100% (3/3), 225 bytes | 225.00 KiB/s, done. Full iii (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/<username>/example.git  * [new branch]      chief -> master Branch 'chief' set upwardly to track remote branch 'primary' from 'origin'.          

Everything worked out nicely this time. So what did we exercise differently? There were two major differences in our arroyo here:

  1. We skipped creating a new co-operative via the branch -Chiliad chief command.
  2. We specified the master branch to push to, using the -f flag to overwrite any existing content (not completely necessary in this case) and the -u flag to set the remote origin as default (makes push commands piece of cake later on)

Final Thoughts

Version control is one of the hallmarks of responsible software development. These powerful tools aren't restricted to professional person 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 exist issued via command line or, as is the example with many mod workflows, via integration with IDEs like IntelliJ or Visual Studio.

I oft find myself working on projects locally without having moved versioning and project files to a Github (or like) remote repository. The procedure to transfer an existing project to Github is outlined poorly past Github and oftentimes fails. I hope the approach outlined here tin can help save some commonage Googling for developers everywhere.

alpharithms discord banner 1

juddsobsell.blogspot.com

Source: https://www.alpharithms.com/adding-existing-project-empty-github-repository-394221/

0 Response to "How to Upload My Existing Projects on Mac to Github"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel