0

I was working on my project and for some reason git add . and git commit -m "message" and git push would not work. So I took my code and uploaded it to the repository. When I did so I ran git clone on the uploaded files and tried to continue my work. Now git push will not work. Its saying

On branch main Your branch and 'origin/main' have diverged, and have 8 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours).

What have I tried and what am I expecting?

I have tried using git reset to a previous commit id and than running the git clone command off that reset repository.

I have tried looking up git rebase but I am working on one repository and not a branch.

I have tried looking at stackoverflow articles such as: When do you use Git rebase instead of Git merge?

I looked at this article: Going back to a previous commit in Github Desktop But I do not see how creating a new branch is going to fix this issue.

What I am running into is, I do not have branches, everything is stored in one remote repoistory. There is only supposed to be one repository. I have learned that not to upload code into the repository when things are working because this whole thing is a mess!

What I am expecting: I am hoping I can get my github to be at commit: 0ace80d Fixing Superuser AND after doing go be able to do git add . and git push.

https://github.com/strikeouts27/django_news_app/commit/0ace80daf934aff633111dddeee1a8a3f2f8b5d4

My GitHub Link: https://github.com/strikeouts27/django_news_app/commits/main

Question is there a way to look at a diagram of whats happening to my repository?

Git Rebase seems promising. It says however that I have unstaged changes. I run git reset to clear them but they will not clear out. I am looking into finding a way to clear them out.

https://www.w3docs.com/learn-git/git-rebase.html

git status output:

(base) andrewstribling@Andrews-MBP news % git status

On branch main Your branch and 'origin/main' have diverged, and have 10 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours)

Changes not staged for commit: (use "git add/rm ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)

    deleted:    ../../../../../.gitignore
    deleted:    ../../../../../.vscode/settings.json
    modified:   ../../../../../README.MD
    deleted:    ../../../../../accounts/__init__.py
    deleted:    ../../../../../accounts/admin.py
    deleted:    ../../../../../accounts/apps.py
    deleted:    ../../../../../accounts/forms.py
    deleted:    ../../../../../accounts/migrations/0001_initial.py
    deleted:    ../../../../../accounts/migrations/__init__.py
    deleted:    ../../../../../accounts/models.py
    deleted:    ../../../../../accounts/tests.py
    deleted:    ../../../../../accounts/urls.py
    deleted:    ../../../../../accounts/views.py
    deleted:    ../../../../../django_project/__init__.py
    deleted:    ../../../../../django_project/asgi.py
    deleted:    ../../../../../django_project/settings.py
    deleted:    ../../../../../django_project/urls.py
    deleted:    ../../../../../django_project/wsgi.py
    deleted:    ../../../../../manage.py
    deleted:    ../../../../../news/README.MD
    deleted:    ../../../../../news/accounts/__init__.py
    deleted:    ../../../../../news/accounts/admin.py
    deleted:    ../../../../../news/accounts/apps.py
    deleted:    ../../../../../news/accounts/forms.py
    deleted:    ../../../../../news/accounts/migrations/0001_initial.py
    deleted:    ../../../../../news/accounts/migrations/__init__.py
    deleted:    ../../../../../news/accounts/models.py
    deleted:    ../../../../../news/accounts/tests.py
    deleted:    ../../../../../news/accounts/urls.py
    deleted:    ../../../../../news/accounts/views.py
    deleted:    ../../../../../news/db.sqlite3
    deleted:    ../../../../../news/django_project/__init__.py
    deleted:    ../../../../../news/django_project/asgi.py
    deleted:    ../../../../../news/django_project/settings.py
    deleted:    ../../../../../news/django_project/urls.py
    deleted:    ../../../../../news/django_project/wsgi.py
    deleted:    ../../../../../news/manage.py
    deleted:    ../../../../../news/pages/__init__.py
    deleted:    ../../../../../news/pages/admin.py
    deleted:    ../../../../../news/pages/apps.py
    deleted:    ../../../../../news/pages/migrations/__init__.py
    deleted:    ../../../../../news/pages/models.py
    deleted:    ../../../../../news/pages/tests.py
    deleted:    ../../../../../news/pages/urls.py
    deleted:    ../../../../../news/pages/views.py
    deleted:    ../../../../../news/templates/base.html
    deleted:    ../../../../../news/templates/home.html
    deleted:    ../../../../../news/templates/registration/login.html
    deleted:    ../../../../../news/templates/registration/password_change_done.html
    deleted:    ../../../../../news/templates/registration/password_change_form.html
    deleted:    ../../../../../news/templates/registration/password_reset_complete.html
    deleted:    ../../../../../news/templates/registration/password_reset_confirm.html
    deleted:    ../../../../../news/templates/registration/password_reset_done.html
    deleted:    ../../../../../news/templates/registration/password_reset_form.html
    deleted:    ../../../../../news/templates/registration/signup.html
    deleted:    ../../../../../pages/__init__.py
    deleted:    ../../../../../pages/admin.py
    deleted:    ../../../../../pages/apps.py
    deleted:    ../../../../../pages/migrations/__init__.py
    deleted:    ../../../../../pages/models.py
    deleted:    ../../../../../pages/tests.py
    deleted:    ../../../../../pages/urls.py
    deleted:    ../../../../../pages/views.py
    deleted:    ../../../../../templates/base.html
    deleted:    ../../../../../templates/home.html
    deleted:    ../../../../../templates/registration/login.html
    deleted:    ../../../../../templates/registration/password_change_done.html
    deleted:    ../../../../../templates/registration/password_change_form.html
    deleted:    ../../../../../templates/registration/password_reset_complete.html
    deleted:    ../../../../../templates/registration/password_reset_confirm.html
    deleted:    ../../../../../templates/registration/password_reset_done.html
    deleted:    ../../../../../templates/registration/password_reset_form.html
    deleted:    ../../../../../templates/registration/signup.html

Untracked files: (use "git add ..." to include in what will be committed)

    ../../../../../.CFUserTextEncoding
    ../../../../../.DS_Store
    ../../../../../.Trash/
    ../../../../../.anaconda/
    ../../../../../.bash_history
    ../../../../../.bash_profile
    ../../../../../.bashrc.save
    ../../../../../.conda/
    ../../../../../.condarc
    ../../../../../.config/
    ../../../../../.continuum/
    ../../../../../.cups/
    ../../../../../.docker/
    ../../../../../.fly/
    ../../../../../.gitconfig
    ../../../../../.idlerc/
    ../../../../../.ipynb_checkpoints/
    ../../../../../.ipython/
    ../../../../../.jupyter/
    ../../../../../.lesshst
    ../../../../../.matplotlib/
    ../../../../../.mono/
    ../../../../../.npm/
    ../../../../../.pgadmin/
    ../../../../../.psql_history
    ../../../../../.python_history
    ../../../../../.ssh/
    ../../../../../.tcshrc
    ../../../../../.venv/
    ../../../../../.viminfo
    ../../../../../.vscode/argv.json
    ../../../../../.vscode/cli/
    ../../../../../.vscode/extensions/
    ../../../../../.xonshrc
    ../../../../../.zprofile
    ../../../../../.zsh_history
    ../../../../../.zsh_sessions/
    ../../../../../.zshrc
    ../../../../../Andrews_First_Jupyter_Notebook.ipynb
    ../../../../../Applications/
    ../../../../../Baseball_Databank/
    ../../../../../Codecademy_Resturant.sql
    ../../../../../DJANGO_Meetup/
    ../../../../.DS_Store
    ../../../../.localized
    ../../../../.ssh:config
    ../../../../6 Popular Data Analytics Certifications_ Your 2023 Guide _ Coursera_files/
    ../../../../Andrew Stribling Pathways.docx
    ../../../../Codecademy learn Data analyst.  copy.pdf
    ../../../../ID THEFT AFFIDAVIT FTC.pdf
    ../../../.DS_Store
    ../../../career/
    ../../../jupyter-data_scientist_salary_projects/
    ../../.DS_Store
    ../../data_job_salaries/
    ../.DS_Store
    ../mysite/
    ../news.zip
    ../../python/
    ../../../questions/
    ../../../resources/
    ../../../../Screen Shot 2023-08-21 at 10.49.51 PM.png
    ../../../../convert_csv/
    ../../../../keyboard-shortcuts-macos.pdf
    ../../../../kobe-angry-949098398.jpg
    ../../../../news/
    ../../../../../Django_Tutorial_Polls_App
    ../../../../../Documents/
    ../../../../../Downloads/
    ../../../../../Library/
    ../../../../../Movies/
    ../../../../../Music/
    ../../../../../Pictures/
    ../../../../../Pipfile
    ../../../../../Pipfile.lock
    ../../../../../Public/
    ../../../../../Untitled.ipynb
    ../../../../../anaconda3/
    ../../../../../andrew-board/
    ../../../../../code with ch1/
    ../../../../../django_for_beginners/
    ../../../../../djangodelights/
    ../../../../../get-pip.py
    ../../../../../gitignore
    ../../../../../jupyter.py
    ../../../../../mysite/
    ../../../../../placeholder.py
    ../../../../../project_env/
    ../../../../../python.py
    ../../../../../untitled.txt
    ../../../../../venv/
    ../../../../../welcome-to-docker/
  • Yes I did git pull when that happened my account reverted but when it revered the django_project folder, which is the main code file was not there. I checked online to see that the django_project folder was present and inside the commit where I want my project. – strikeouts27 Aug 26 '23 at 02:05
  • git pull output: (base) andrewstribling@Andrews-MBP news % git pull remote: Repository not found. – strikeouts27 Aug 26 '23 at 02:27
  • git pull from ssh output: (base) andrewstribling@Andrews-MBP news % git pull git@github.com:strikeouts27/django_news_app.git From github.com:strikeouts27/django_news_app * branch HEAD -> FETCH_HEAD Already up to date. – strikeouts27 Aug 26 '23 at 02:28
  • the main file folder django_project is missing from this commit. but when I go to github and look at the commit the django_project folder is there. – strikeouts27 Aug 26 '23 at 02:31
  • If I downloaded the folder and just placed it in my project and did a git add do you think I could get away with that? – strikeouts27 Aug 26 '23 at 02:34
  • 1
    ... but to be honest ... you shouldn't need to. I don't think you are working in a correct repository. Maybe you are inside a repository inside another repository or some other kind of shenanigans. Do a proper clone and get your folders right. – topsail Aug 26 '23 at 02:40
  • what i mean is, this kind of stuff in untracked files is nonsense: `../../../../../.bash_history` ... it appears you are trying to add your entire home folder (or pretty much all your files everywhere) to a repository. Not good. So you may have created a git repository in the root of your home folder ... not good either. – topsail Aug 26 '23 at 02:42
  • I will try to do a git clone from a prior point in time. I wil llet you know once I have done so. should take 2 min – strikeouts27 Aug 26 '23 at 02:46
  • okay look for rogue git repos in your home folder or other top level folders (show and search for the hidden `.git` folders to find them). If one exists it may be causing headaches. – topsail Aug 26 '23 at 02:48
  • I am new to all of this. I have opened the folders on my macbook and I do not see the .git files anywhere. I will look up how to find them via google search. – strikeouts27 Aug 26 '23 at 02:51
  • none of the commands seem to be working. git clone is saying fatal repository not found when I type in git clone SHA or the url. – strikeouts27 Aug 26 '23 at 02:56
  • I did command shift . and none of the hidden file folders are appearing. The whole thing is a mess. perhaps I should download the commit and the files that I want and than delete the whole repository and be willing to sacrifice the prior commits. Just to get back on track. – strikeouts27 Aug 26 '23 at 02:56
  • forgive my ignorance for I am new. It seems adding .git to my .gitignore folder managed to stop the ../ from happening. – strikeouts27 Aug 26 '23 at 04:39
  • That's a horrible solution - you should not need to add .git to a .gitignore folder. You have some mess here. I suggest you find and remove all your git repositories, then start over clean. Stop putting git repositories in git repositories. Don't make your entire home folder or your whole computer a git repository. A git repository should have only one project in it - not a folder full of projects (I am speaking for beginners - there may be use cases but you need to get the basics first). – topsail Aug 26 '23 at 16:12

1 Answers1

0

git remote add origin was the command I needed to re establish a new repository. I did lose my commits in the process of deleting the repository but now at least I am able to start a new github repository with my mostly up to date code.