-2

I wrote these commands

git init -b main
git add .
git commit -m "initial commit"
git remote add origin https://github.com/sevoashraf499/OBARS.git
git push -u origin main

this gave me an error and I tried to solve it with these commands

git pull --rebase origin main
git pull origin main

but this deleted my local project enter image description here enter image description here enter image description here

  • 1
    Your question misses the output of these commands, especially the revisions that were overwritten. In such a case take a look into the `reflog` and restore the revision you're looking for. This works unless those revisions are garbage collected. – hakre May 19 '23 at 05:28
  • Does this answer your question? [Undoing a git rebase](https://stackoverflow.com/questions/134882/undoing-a-git-rebase) – hakre May 19 '23 at 05:30
  • i wrote reflog and gave me this bash: reflog: command not found – Steven Ashraf May 19 '23 at 05:30
  • Yes, it requires learning first. Reading experience of technical documentation recommended, the git documentation is available at https://git-scm.com/doc - double check the version of git you're using. Learn how to make backups first, especially from git repositories as git is not a backup software just version control. – hakre May 19 '23 at 05:32
  • yes, I will learn it – Steven Ashraf May 19 '23 at 05:34
  • but for now is there any way to recover these files? – Steven Ashraf May 19 '23 at 05:34
  • When @hakre said "look into the `reflog`", he meant you to run `git reflog`. – LeGEC May 19 '23 at 05:39
  • Also, still paraphrasing hakre's comments, "the output of these commands" include the *error messages* of these commands. `git pull` can fail for quite a number of reasons (network issues ? access rights ? hooks ? conflicts ? ...), if we don't know which reason we can merely blind guess your issue. – LeGEC May 19 '23 at 05:43
  • Worth knowing : your basic go to command to check the state of your repository is : `git status` – LeGEC May 19 '23 at 05:43
  • Good idea, please add the output of `git status` and `git reflog` to your question by [edit]ing it. And this perhaps gives better explanations as a duplicate: https://stackoverflow.com/q/10907173/367456 – hakre May 19 '23 at 05:45
  • I tried the solution you've suggested and I followed the steps and added the output of git reflog and git status to the question – Steven Ashraf May 19 '23 at 05:51
  • If you would now even be so eager and add the information not only as a screenshot but as text would be great. Let us know if you need more help editing the question. – hakre May 19 '23 at 06:32
  • 2
    and try: `git rebase --abort` (single command line) if it already solves your problem. @LeGEC was spot on with the `git status` suggestion. – hakre May 19 '23 at 06:34
  • Do not post pictures of text. – matt May 19 '23 at 10:17

1 Answers1

2

The status of your repo shows you are actually in the middle of the rebase on top of the pulled branch.

Try running git rebase --continue to proceed with your rebase.

If it doesn't work: given the current state of your github repository (at the moment: only one single commit with a basic README file which I assume was created through the web GUI of github), you can simply overwrite it :

git rebase --abort
git push --force-with-lease origin main

You may re-add a README file in your next commit.

LeGEC
  • 46,477
  • 5
  • 57
  • 104