Title: Git tip: Changing your mind: Push pending changes to a (not-yet existing) new branch
Author: Alex Kirk
Published: February 15, 2012

---

# Git tip: Changing your mind: Push pending changes to a (not-yet existing) new branch

February 15, 2012

It happens quite often to me that I start committing things and only afterwards 
decide I should have created a new branch.

So `git status` says something like:

`Your branch is ahead of 'origin/master' by 4 commits.`

 but I don’t want to push to origin/master but rather create a new branch. (Of 
course this works for any other branch, not named master)

So you can use **this sequence of commands**:

`git checkout -b _newbranch_
 git push origin _newbranch_ git checkout master git
reset --hard origin/master

Explanation: This…

1. creates a new branch pointing to the current changes (and switches to it)

2. pushes this new branch including the changes to the server

3. switches back to the branch master
 4. and undoes the changes that were made 
locally

The important thing to know is that the changes remain in the repository because
a branch is merely a pointer to a commit.

Afterwards you can continue to commit to master, for example:

(screenshots done with a fork of [gitx](http://rowanj.github.com/gitx/))

[Web](https://alex.kirk.at/category/web/)

Read this next

[hckr news](https://alex.kirk.at/2012/01/26/hckr-news/)

### Leave a Reply 󠀁[Cancel reply](https://alex.kirk.at/2012/02/15/git-tip-changing-your-mind-push-pending-changes-to-a-not-yet-existing-new-branch/?output_format=md#respond)󠁿

Only people in [my network](https://alex.kirk.at/friends/) can comment.

This site uses Akismet to reduce spam. [Learn how your comment data is processed.](https://akismet.com/privacy/)