Skip to content

Instantly share code, notes, and snippets.

@alexpchin
Created June 1, 2014 20:14
Show Gist options
  • Save alexpchin/102854243cd066f8b88e to your computer and use it in GitHub Desktop.
Save alexpchin/102854243cd066f8b88e to your computer and use it in GitHub Desktop.
Add Existing Project To Git Repo

#Adding an existing project to GitHub using the command line

Simple steps to add existing project to Github.

1. Create a new repository on GitHub.

In Terminal, change the current working directory to your local project.

##2. Initialize the local directory as a Git repository.

git init

Add the files in your new local repository. This stages them for the first commit.

git add .

or:

git add --all

Commit the files that you've staged in your local repository.

git commit -m 'First commit'

Copy remote repository URL field from your GitHub repository, in the right sidebar, copy the remote repository URL.

In Terminal, add the URL for the remote repository where your local repostory will be pushed.

git remote add origin <remote repository URL>

Sets the new remote:

git remote -v

Push the changes in your local repository to GitHub.

git push origin master

Pushes the changes in your local repository up to the remote repository you specified as the origin

@craigphicks
Copy link

😆

@heliniApps
Copy link

Thank you for the commands and steps.

Just sharing another way I used to connect my locally initialised 'empty repository' to the already existing remote Git Repo.
My remote repository already had files in it.
I could also clone the remote repository, but just wanted to try pulling the remote changes, instead of pushing the local files first.

To connect the local repo to the existing Git Repository and pull down changes:

  • git init -b main
  • git remote add origin <REMOTE_URL>
  • Check if it's setup correctly using git remote -v
  • git fetch
  • git pull <repository> <branch>
    • e.g.: git pull origin main
    • This will pull the remote "main" branch (origin/main) changes/files, and create the 'main' branch locally.
  • Use git branch command to make sure the "main" branch is created locally.

To push any new local changes (after pulling the remote changes as described above):
  • Make changes to the files.
  • git add <file>
  • git commit
  • git push -u origin <branch>
    • e.g.: git push -u origin main

@lgirao
Copy link

lgirao commented Mar 13, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment