I forgot to checkout branch before making changes

I added a new branch to my git repository for a new feature I was adding and forgot to explicitly check it out. I have since changed a lot of files without committing, but I want to be able to commit these changes to the alternate branch, not the master. How can I do this safely?

  • How to tell git to ignore individual lines, i.e. gitignore for specific lines of code
  • How to get tags on current commit
  • List ALL the files that ever existed in ANY branch in a git repository
  • COM reference name changes across versions (Win7 CERTCLIENTLib to Win8 CERTCLILib)
  • Git Bash Open Command Windows
  • Process full content of git blame
  • How can sbt pull dependency artifacts from git?
  • Ignore deleted files in git?
  • Switch to another branch without changing the workspace files
  • How do I prevent git on Cygwin to set core.filemode=true
  • How can I “git log” only code published to trunk?
  • How to clean a remote GIT repository?
  • 2 Solutions collect form web for “I forgot to checkout branch before making changes”

    You can just checkout the new branch – your uncommitted changes will be carried over to the new branch. (This isn’t allowed if your local changes would affect a file that would be changed by switching branch, but in this case it sounds as if the new branch is at the same position as your last commit, so that won’t be a problem.)

    git stash
    git checkout other_branch
    git stash pop

    Ought to do the trick. You can then commit as normal. See also: git stash manual page

    Git Baby is a git and github fan, let's start git clone.