regrouping commits
# back to master & up-to-date:
git checkout master
git pull
# create a new clean branch
git checkout -b clean_new_feature
# merge in the branch with ton of commits
git merge messy_feature
# The clean_new_feature branch now has everything needed.
# Move its pointer back to the origin so our merge is considered
# a series of unstaged changes:
git reset origin/master
git status # review the differences :)
git add .
git add -u # you wants to send file deletions too
git commit
You now have all the commits regrouped in one new branch named 'clean_new_feature'. You can now request a pull&merge to upstream.
advancing remote branch
(master)$ git checkout -b localbranch nickname/master
Branch localbranch set up to track remote branch master from nickname.
Switched to a new branch 'localbranch'
(localbranch)$ git merge origin/master
Updating 1234567..9abcdef
Fast-forward
...
X files changed, Y insertions(+), Z deletions(-)
(localbranch)$ git status
# On branch localbranch
# Your branch is ahead of 'nickname/master' by T commits.
#
nothing to commit (working directory clean)
(localbranch)$ git push
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:nickname/repository.git
1234567..9abcdef master -> master
(localbranch)$ git status
# On branch localbranch
nothing to commit (working directory clean)
(localbranch)$
pushing local branch to a remote branch
$ git push nickname localbranch:remotebranchname
This would push your local branch named 'localbranch' to the 'nickname' repository under the branch name 'remotebranchname'. Simple isn't it?