I\'ve done a fair bit of work (\"Your branch is ahead of \'origin/master\' by 37 commits.\") which really should have gone into its own branch rather than into master<
One more way assume branch1 - is branch with committed changes branch2 - is desirable branch
git fetch && git checkout branch1
git log
select commit ids that you need to move
git fetch && git checkout branch2
git cherry-pick commit_id_first..commit_id_last
git push
Now revert unpushed commits from initial branch
git fetch && git checkout branch1
git reset --soft HEAD~1
If you have a low # of commits and you don't care if these are combined into one mega-commit, this works well and isn't as scary as doing git rebase
:
unstage the files (replace 1 with # of commits)
git reset --soft HEAD~1
create a new branch
git checkout -b NewBranchName
add the changes
git add -A
make a commit
git commit -m "Whatever"
Checkout fresh copy of you sources
git clone ........
Make branch from desired position
git checkout {position}
git checkout -b {branch-name}
Add remote repository
git remote add shared ../{original sources location}.git
Get remote sources
git fetch shared
Checkout desired branch
git checkout {branch-name}
Merge sources
git merge shared/{original branch from shared repository}
Here is a much simpler way:
Create a new branch
On your new branch do a git merge master
- this will merge your committed (not pushed) changes to your new branch
Delete you local master branch git branch -D master
Use -D
instead of -d
because you want to force delete the branch.
Just do a git fetch
on your master branch and do a git pull
on your master branch to ensure you have your teams latest code.