Search code examples
gitgithubgithub-pages

How to Resume Git Repository After Operating System Restore


I have searched extensively for an answer to my situation to no avail. Please forgive me if this has been answered and I just for some reason couldn't find it.

I recently completely wiped my hard drive and reinstalled my OS (Xubuntu 20.04). After getting the OS installed, I synchronized all my files from my local backup to the restored system, which included the git repository I had on the previous OS install. Well, I made changes to one of the files in my repository and went to do a git status and I got a message saying, "Your branch is up-to-date."

I tried some things like, git fetch, git init, and still the same message as above.

Well, I read somewhere to remove the .git folder and do git init again and then git add . then git commit -m "Message" and then git push -u origin master. Now, I'm getting the message,

"fatal: 'origin' does not appear to be a git repository.

fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists."

If anyone could pleas give me some guidance on this issue, I would greatly appreciate it. Thanks in advance.


Solution

  • You need to add origin to your git repository because you have removed the .git folder. Try the following

    git remote add origin https://github.com/user/repo.git
    # Set a new remote
    
    git remote -v
    # Verify new remote
    origin  https://github.com/user/repo.git (fetch)
    origin  https://github.com/user/repo.git (push)
    

    For more details click here. Then push your changes to the git using

    git push origin master
    

    Don't forgot to move your ssh keys back to ~/.ssh directory if you have a backup of them otherwise create new ssh keys

    For pulling the latest data from repo., use git pull