I am new to working with Git. I made changes to a website in a local folder. When I wanted to push them through, an error occurred:
[rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/id/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
I made the suggested pull request, unaware that this would erase all my local changes.
My terminal still shows the previous commands and commits. Is there a way to restore my local folder to the previous version, from before the pull request?
So a résumé:
- I tried to push commits through, but they were rejected. I don't understand why.
- I then did
git pull <branch>, unaware it would erase my local changes. - I then did a Git reset, hoping it would erase my last action.
I will try to order your thoughts quickly
Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.In other words: on your server (remote) are changes, that you do not have locally in your current branch. Git does not know how you want to proceed with these changes.git pull. From what I can tell you don't a pull request, you want do update your current local branch viagit pull. Do not confuse pull requests withgit pullhttps://git-scm.com/docs/git-pullgit resetis one of the few dangerous commands that may destroy code changes. Be careful using that command and learn about it first. It is not meant for "erasing your last git action".gitk(tool that is always installed with git) to view the history, create a branch, merge and visualize what you are doing.git checkout <yourCommitHash> -b NewBranchto create a new branch on your commit and check it outgit merge <currentLocalBranchto merge your current local branch into your NewBranchgit push