Skip to content

Instantly share code, notes, and snippets.

@davehague
Forked from alexpchin/Add_Existing_Project_To_Git.md
Last active September 19, 2024 14:23
Show Gist options
  • Save davehague/1d1e28306c1d4a85e918f7513ee9453a to your computer and use it in GitHub Desktop.
Save davehague/1d1e28306c1d4a85e918f7513ee9453a 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

  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

  3. Add a gitignore file thats specific to your project Find examples here: https://www.toptal.com/developers/gitignore

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

    git add . or git add --all

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

    git commit -m 'First commit'

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

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

    git remote add origin <remote repository URL>

  8. Confirm the configured remotes:

    git remote -v

  9. Rename master to main

    git branch -m master main

  10. Push the changes in your local repository to GitHub.

    (override the remote)

    git push -f origin main

    (don't override the remote)

    git push origin main

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