1

I had a computer running some software, that I had/have in a github repo. I just got some new hardware, and moved to that, basically just copied all files (incl. .gitignore) to the new hardware.

How do I make the new directory on the new hardware "continue" in the github repo? Can I just do something like:

git init
git add .
git commit -m 'MESSAGE'
git remote add origin https://github.com/Aephir/Home_Assistant
git push -u origin master

Or would this cause problems? I will no longer push from the old hardware, and this is something that will only ever be pushed from one place (new hardware/directory), in case that matters. The git repo is mostly just to be able to share my config with the community, no one else is modifying anything and/or committing.

Cheers!

Aephir
  • 157
  • 6

3 Answers3

2

I do not suggest the procedure you asked about; creating a new commit locally and then trying to attach it to the existing repo would cause problems.

If you copied everything (includeing the hidden ./git directory) then it should already be recognized as a working repository. If it doesn't, two things to check:

1) The .git/ directory, which contains all of the repo metadata, needs to be included in the copy. You mention the .gitignore file, which is possibly important for other reasons but is not sufficient to define the directory as a repo

2) Make sure the git software itself is properly installed

But really the easiest thing to do IMO is, instead of copying the directory at all, just create an empty directory on the new machine / at the new location / whatever, and run git clone. That way, either clone works and you know everything is set up correctly, or it fails with an error message that points you in the correct direction for a fix.

The only potential drawback is if the working directory for the repo aslo contained a lot of untracked / ignored files (other than just those that might be auto-generated by a build). Those you might well have to copy, but depending on the situation it still might be worth copying only those files into a new working directory created by git clone.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • I would prefer a `git clone`, because everything is set up from scratch. Error could quickly occur during copying... – SwissCodeMen May 04 '20 at 17:06
1

You do not have to initialize the file again. You can start working from there after you copy the folder. Then commit and push to the remote repository after editing. Be sure to move the whole directory. The metadata that git needs to run is stored in hidden files in the project's directory.

Gayal Kuruppu
  • 1,261
  • 1
  • 17
  • 29
  • I would suggest a `git clone`, if everything is up to date on the github server. This way you can avoid possible errors and clone the repo really new! – SwissCodeMen May 04 '20 at 14:38
  • 1
    As you said, it was ready to continue work. I guess I should have tried committing before asking, I was just a bit worried about messing something up. But thanks! – Aephir May 05 '20 at 13:28
  • Sure. I also set it as solution (since this was the first) – Aephir May 05 '20 at 13:35
1

You only use git init if you have code and you want to put it in a new Git repo.

In your case, you have code, but you don't want to put it in a Git repo. You want to pull an existing repo, locally to your computer. For this, you can navigate to your folder where you the Git repo want and write git clone <url_to_github_repo>. Then git clone is basically a combination of git init, git remote add, git fetch and git checkout.

Therefore you can just write: git clone https://github.com/Aephir/Home_Assistant and you will have the git repo locally on your computer

git clone documentation

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34