Skip to content

Instantly share code, notes, and snippets.

@alexpchin
Created June 1, 2014 20:14
Show Gist options
  • Select an option

  • Save alexpchin/102854243cd066f8b88e to your computer and use it in GitHub Desktop.

Select an option

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

@IArnaut2
Copy link
Copy Markdown

IArnaut2 commented May 31, 2026

Can anyone help me?

PS D:\Documents\_Dokumenti\Projekti\_Master\Real Estate App\Laravel\secure> git push -f origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/IArnaut2/Real-Estate-Laravel-Secure-App.git'

I also tried fetching and pulling the repository.

PS D:\Documents\_Dokumenti\Projekti\_Master\Real Estate App\Laravel\secure> git fetch
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 1.05 KiB | 215.00 KiB/s, done.
From https://github.com/IArnaut2/Real-Estate-Laravel-Secure-App
 * [new branch]      main       -> origin/main
PS D:\Documents\_Dokumenti\Projekti\_Master\Real Estate App\Laravel\secure> git pull origin main
From https://github.com/IArnaut2/Real-Estate-Laravel-Secure-App
 * branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories

@IArnaut2
Copy link
Copy Markdown

git merge origin/main --allow-unrelated-histories worked, but I still couldn't push the local files to the repository.
My repository: https://github.com/IArnaut2/Real-Estate-Laravel-Secure-App.

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