Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect a local folder to an existing github repo?

I made a repo on my laptop. It has a project page on github.com.

I'm now working on my desktop computer. I manually copied over some files because I didn't think I would need every file from the repo (so I didn't clone the repo onto my desktop). How can I connect my desktop local folder with the existing repo so that I can push the files on my desktop to the repo (the desktop files are now the most recent versions of those files, since I stopped working from my laptop)

like image 765
oiwrjgoirjgio Avatar asked Apr 25 '18 15:04

oiwrjgoirjgio


People also ask

How do I add a local file to a Git repository?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.


2 Answers

Adding an existing project to GitHub using the command line:

# Initialize the local directory as a Git repository.
git init

# Add files
git add .

# Commit your changes
git commit -m "First commit"

# Add remote origin
git remote add origin <Remote repository URL>
# <Remote repository URL> looks like: https://github.com/user/repo.git

# Verifies the new remote URL
git remote -v

# Push your changes
git push origin master

And 2nd way as @evolutionxbox suggest you:

  • Clone git repo
  • Copy and paste into it
  • Push your change at origin

If in any case git reject your push you can use git push origin master --force

UPDATE (10-23-2020): Bear in mind that since October 1st, 2020, Github renamed the default repository from master to main https://github.com/github/renaming

like image 70
Asif Raza Avatar answered Oct 12 '22 03:10

Asif Raza


  1. Create a local repository in the temp-dir directory using: git clone temp-dir

  2. Go into the temp-dir directory.

  3. do a git branch -a

  4. Checkout all the branches that you want to copy from origin using git checkout branch-name

You are done

like image 32
Jemmy Fred Avatar answered Oct 12 '22 02:10

Jemmy Fred