Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

GitHub Project Recovery Guide

A practical guide to restoring GitHub project links after system reinstallation, fixing Git issues, resolving merge conflicts, and replacing remote repository contents.

GitHub Guide Git Tutorial README Friendly


πŸ“š Contents


πŸš€ 1. Fix Git Not Recognized

Problem

Running the git command shows:

git: command not found

This usually means Git is not installed correctly or the environment variable is missing.

Solution

  1. Install Git from the official website: Git Download for Windows
  2. Add Git to the system Path environment variable:
    • C:\Program Files\Git\bin
    • C:\Program Files\Git\cmd
  3. Restart Git Bash or terminal, then verify:
git --version

If a Git version is displayed, the installation is successful.

Tip

After editing the environment variable, restart your terminal before testing.


πŸ”§ 2. Recover a Project Without .git

Scenario

You still have your project files, but the .git folder is missing. Running commands like git remote -v gives:

not a git repository

What This Method Does

  • Keeps your existing project files
  • Reconnects the project to GitHub
  • Rebuilds Git tracking
  • Does not restore old local commit history

Commands

Replace YOUR_REPOSITORY_URL with your actual GitHub repository URL. Replace main with master if your remote branch uses master.

# 1. Initialize a new local Git repository
git init

# 2. Connect to the remote GitHub repository
git remote add origin YOUR_REPOSITORY_URL

# 3. Verify the remote
git remote -v

# 4. Add all files
git add .

# 5. Commit locally
git commit -m "Restore project files after system reinstallation"

# 6. Pull remote history and allow unrelated histories
git pull origin main --allow-unrelated-histories

# 7. Push and set upstream
git push -u origin main

Warning

This method restores Git tracking, but it does not recover your original local commit history.


⚠️ 3. Resolve Merge Conflicts

Problem

When pulling from remote, you may get:

CONFLICT (add/add): Merge conflict in README.md

Solution

Open the conflicted file and remove conflict markers like:

<<<<<<<
=======
>>>>>>>

Then manually merge the content you want to keep.

Commands After Fixing the Conflict

# Add the resolved file
git add README.md

# Commit the merge result
git commit -m "Resolve README merge conflict"

# Push again
git push -u origin main

Tip

Read the conflicting sections carefully before deleting markers, especially in documentation files like README.md.


πŸ“ 4. Troubleshoot Wrong Project Path Issues

Problem

Git says:

Everything up-to-date

But the local files and GitHub repository content look different.

Possible Cause

You may be operating in the wrong local folder.

Check Current Directory

pwd
cd /path/to/the/correct/project

Verify Local and Remote Commit IDs

git rev-parse main
git rev-parse origin/main

If both commit IDs are the same, the local and remote branches are synchronized.

Extra Checks

  • Refresh the GitHub webpage
  • Restart your editor or IDE
  • Confirm you are editing the same folder that Git is tracking

πŸ—‚οΈ 5. Replace All Contents in a Remote Repository

There are two common ways to replace all files in a GitHub repository.

Method 1: Delete Files from GitHub Web Interface

Recommended for beginners.

  1. Open the repository on GitHub
  2. Delete existing files manually from the web interface
  3. Commit the deletion
  4. Push your new local project files:
git add .
git commit -m "Upload complete new project content"
git push -u origin main

Method 2: Clear and Replace Using Command Line

Use this carefully. Make sure you understand what will be deleted.

# 1. Pull latest remote changes
git pull origin main

# 2. Remove tracked project files locally
rm -rf *

# 3. Commit deletion and push
git add .
git commit -m "Clear all existing repository content"
git push origin main

# 4. Add your new project files, then commit and push again
git add .
git commit -m "Upload complete new project content"
git push -u origin main

Important Note

The command below:

rm -rf *

does not always remove hidden files. Double-check the directory manually before proceeding.

Warning

Be extra careful when using rm -rf *, especially in the wrong directory.


πŸ–₯️ 6. GitHub Desktop Remote Setup

If you use GitHub Desktop:

  1. Go to File β†’ Add Local Repository
  2. Select your local project folder
  3. Open Repository β†’ Repository Settings
  4. In the Remote section, add your GitHub repository URL
  5. Save the settings

πŸ’‘ 7. Important Tips and Pitfalls

1. Always keep the .git folder when backing up a project

If the .git folder is lost, your code files remain, but the full local Git history is gone.

2. Be careful with force push

git push -f origin main

This can overwrite remote history.

3. Back up the repository before major operations

Before clearing or replacing repository contents, create a backup if needed.

4. Check branch names

Some repositories use main, others use master.

Use this command to check remote branches:

git branch -r

Tip

Always confirm the remote default branch before pushing.


βœ… Recommended Workflow

If your project files still exist but .git is missing, the safest basic flow is:

git init
git remote add origin YOUR_REPOSITORY_URL
git add .
git commit -m "Restore project files"
git pull origin main --allow-unrelated-histories
git push -u origin main

About

A practical guide to restoring GitHub project links, recovering repositories after system reinstallation, resolving merge conflicts, and replacing remote repository contents.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors