0

there. I made a mistake in Git. I had a code in Development branch, on which i was working And i needed to use git command

git branch newBranch
git checkout newBranch
git add .
git commit -m 'something'
git push origin newBranch

To push my changes from newBranch And instead of this i excedently wrote

 git add .
 git commit -m 'something'

Is there a way how to send it from newBranch ?

I tried to move from Development branch to newBranch and run same commands, but it didn't work:(

Karina Shulan
  • 161
  • 1
  • 9
  • it's not clear what you did and neither it's clear what you meant to do instead – Diego D Apr 01 '22 at 13:02
  • @Dieg De Vita I needed to push my changes which were in Development branch from newBranch and instead of it i made a commit in Development – Karina Shulan Apr 01 '22 at 13:05
  • if you didn't push your wrong commit, you can still revert to the previous state on a given branch doing `git reset --soft HEAD~1`. That will undo the latest commit on that branch. After that you'll find your now uncommitted changes.. checkout to the branch where you are meant to commit those changes and just do it. – Diego D Apr 01 '22 at 13:09

1 Answers1

0

You should be able to push to any branch from any branch. A fast method I generally use would be to

git checkout -b someBranch origin/newBranch
git add -A
git commit -m "SupDo"
git push origin someBranch

Now, there could be some rule upstream that prevents you from pushing to the branch in question. If lets say, you wanted to move development branch to newBranch1, you can simply

git checkout -b newBranch1 origin/development
git add -A
git commit -m "Init newBranch1"
git push origin newBranch1

newBranch1 should have everything from origin/development. Hope this helps. :)

  • As well, if you have committed to a branch unintentionally, simply do a `git log branchname` find the commit before the one you accidently made and reset the branch to that hash by running the following. ``` git checkout branchWithBadCommit git reset --hard COMMITHASH git add -A git commit -m "Reverting to Good Commit" git push -f origin branchName ``` – TheBirdWingedDragon Apr 01 '22 at 13:13