
- #Commit and push to a different branch not master git how to
- #Commit and push to a different branch not master git trial
Oh shit, I need to change the message on my last commit! git commit -amend Warning: You should never amend commits that have been pushed up to a public/shared branch! Only amend commits that only exist in your local copy or you're gonna have a bad time. You could also make the change as a new commit and then do rebase -i in order to squash them both together, but this is about a million times faster. and FML, I didn't put a space after an equals sign. This usually happens to me if I commit, then run tests/linters. # now your last commit contains that change! Mega hat tip to the many many many many many people who suggested adding it! Oh shit, I committed and immediately realized I need to make one small change! # make your change

You can use this to get back stuff you accidentally deleted, or just to remove some stuff you tried that broke the repo, or to recover after a bad merge, or just to go back to a time when things actually worked. # each one has an index find the one before you broke everything # you will see a list of every thing you've Oh shit, I did something terribly wrong, please tell me git has a magic time machine!?! git reflog So here are some bad situations I've gotten myself into, and how I eventually got myself out of them in plain english.
#Commit and push to a different branch not master git how to
Git documentation has this chicken and egg problem where you can't search for how to get yourself out of a mess, unless you already know the name of the thing you need to know about in order to fix your problem. The last thing to do is delete my tmp branches.Git is hard: screwing up is easy, and figuring out how to fix your mistakes is fucking impossible. To finish things up, I’ll just push my changes and then rebase my feature branch which will reorder my commits to match the master branch and place my feature commits as the last three commits in the log. Now in the log, I can see the history is in the correct order, just how I wanted it. Next, I merge my tmp branch into the master branch. After deleting the commits, I just save and quit my editor. This will give me the history I want with the 4th commit coming right after the last commit on the master branch. This loads the commits into my editor and from here I just delete the 3 commits that I didn’t want on my master branch. For simplicity in the commands here, we’ll just use SHA-MASTER in place of the actual SHA1 hash. I want to rebase everything back to the last commit on the master branch. I’m going to rebase this branch using interactive mode.

This will give me the history that I want, but will include the 3 commits I don’t want. Now I’m going to merge the two tmp branches so that I have a history that contains all of my commits. I’ll do the same for master so that I can perform my merging and rebasing in isolation from the master branch. Next, I’ll create a temporary feature branch that I’ll use later on to bring over the commit that I want. Then I’ll checkout my feature branch and make sure it’s completely up to date with the master branch. In the current scenario, the feature branch is 4 commits ahead of the master and the branch that I want to bring over is just the most recent.įirst things first, I need to ensure my master branch is up to date. The branches I’ll be working with are master and feature. This may not be the simplest approach, but it worked for me and wanted to share.
#Commit and push to a different branch not master git trial
After some digging and a little trial and error, I finally figured it out.

Git rocks at manipulating branches and I knew this, but I wasn’t sure how to just move one commit to the master branch. Suddenly you realize that you need to merge just the fix you made, but don’t want to merge the commits from the previous feature your working on. So, you jump right in and fix the issue and then you realize you forgot to start a new git feature branch. You’re right in the middle of developing a feature when a request comes up to fix a different completely unrelated problem. Perhaps you’ve made the same mistake I have.
