I was creating feature
branches and merging them with my master
branch during development.
Now I need to push only certain feature
branches to another remote, but they are all merged with my master
(and other feature
branches). What would be the best practice for that?
Edit:
If you merged master
into the feature-branch
, revert the changes until one commit before the merge and create a new branch with git checkout -b undo-merge
. Then use git cherry-pick
with either --skip
to skip the merge commit or just apply all other commits after that.
Old answer
You most certainly did not delete the local branches, just check them out and push separately:
git branch -a # lists all branches locally
git checkout feature-branch
git push origin feature-branch # pushes this branch only to the remote "origin"
If you deleted them, you need to figure out the commit hash, (search the mearge with git log
and then check out the hash, create a new branch and push it again:
git checkout "hash"
git checkout -b feature branch
... # repeat above
hope this helps.
In many workflows, once a feature
branch has been merged back into master
it is deleted. GitHub is probably the prime example of this. If you follow this school of thought, you would delete that and create a new feature branch for your next sprint.
If you really want to keep using the branch, then you will either have to rebase the feature
branch on master
or merge master
into feature
branch. I don't see any advantage to rebasing, which could be messy, so let's consider merging. You merged feature branch into master. Therefore master already has all the features from feature branch but the reverse is not true, ie feature branch is likely missing several features which have been introduced into master. To do the merge you would use this command:
git checkout feature
git merge master
You may have to resolve merge conflicts arising from new features in master
which are not yet in the feature branch.
Now the feature
branch is up to date with master
, and you can keep using it if you wish. Personally, I would just leave feature branch where it is and create an entirely new feature branch. You can keep it around for a few sprints until you are sure that deleting it safe.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.