-1

I've basically re-coded an entire project that I previously had from a year ago. Instead of deleting the repo, how can I just recommit so that I can still keep the old project history? This is the error I keep getting when I try to commit.

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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I did try git pull. Very hesitant to continue because I don't want to mess up current code or previous code.

git log:

* a7b0452 (HEAD -> master) Entire Refactor
* 64f072c Initialize project using Create React App
* 7b8b043 (origin/dependabot/npm_and_yarn/handlebars-4.5.3) Bump handlebars from 4.1.2 to 4.5.3
* fabab5b (origin/master) Update README.md
* e1de773 Update README.md
* fbee064 added react-router
* efa9634 flexbox
* fc21821 refactored and fixed state issue
* 67f7091 cash-flow statements
* 86f24f0 cashflow + balance sheet
* f9b597f cards
* a7a2bac netlify redirect
Teddy Smith
  • 33
  • 2
  • 5
  • run `git fetch --all` and then `git log --all --graph --oneline` and send the output here. don't worry! these commands doesn't have side-effect on your current state. – Mahdi Aryayi Feb 20 '20 at 15:48
  • ```* a7b0452 (HEAD -> master) Entire Refactor\n * 64f072c Initialize project using Create React App * 7b8b043 (origin/dependabot/npm_and_yarn/handlebars-4.5.3) Bump handlebars from 4.1.2 to 4.5.3 fabab5b (origin/master) Update README.md \n e1de773 Update README.md fbee064 added react-router efa9634 flexbox fc21821 refactored and fixed state issue 67f7091 cash-flow statements 86f24f0 cashflow + balance sheet f9b597f cards a7a2bac netlify redirect``` – Teddy Smith Feb 20 '20 at 15:50
  • 2
    This is not readable at all! please send it in your question as an update and please keep indentation as you saw in your terminal, so I can read the output. you can use a code block to show them in stackoverflow – Mahdi Aryayi Feb 20 '20 at 15:57
  • Got it. Updated! – Teddy Smith Feb 20 '20 at 16:12
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Feb 20 '20 at 16:20
  • I realise the question is now closed for being a duplicate, but for future reference you should put *all* relevant details into your question. That means it is not sufficient to write "I did try git pull". You need to explain what happened when you tried, so that we can understand why that did not solve your problem. – JBentley Feb 20 '20 at 16:40

1 Answers1

0

The best solution I can recommend is keeping new and old projects in different branches.

git checkout origin/master;
git branch old-master;
git checkout old-master;
git push origin old-master;
git checkout master;
git push origin master -f;

Now your old code is on old-master and new code on master

Mahdi Aryayi
  • 1,090
  • 7
  • 13