how to remove commits from master branch and put them into a new development branch

carmonkey
carmonkey
so i made 2 commits to the master branch but now i want to move them to a new branch called development how can i do that. i push all the commits to github if that may cause a problem. any help appreciated sorry if this is the wrong place to put the question

Last updated

DougR
DougR
Once a commit is pushed upstream it is "extremely impolite" to remove them since when that happens any clone that has that commit will become invalid and work done by the person who has that clone will need to be redone. I assume that what you mean by "moving 2 commits" would entail creating the branch based on the latest commit - but then removing the 2 commits from the master branch. If so you'd be breaking that rule. Now the rule has been broken before and will be broken again based on normally based on inappropriate content (e.g. 3rd party licensed software contaminating a source base). It's also possible that what's been pushed upstream isn't being used by anyone. The longer that the commits are still in the upstream repo the more rework will be needed and therefore the less feasible it is to remove (unless it's a "must"). Moving it to a branch is easy: just create the branch off the version before the 2 commits, merge the 2 commits in (should be fast-forward) and then push the new branch upstream. Removing the 2 commits is more difficult and will require appropriate permission on the upstream repository (forced push must be allowed) and the use of the "--force" option to the "git push" command. You'll need to check with github on how to enable a forced push.
carmonkey
carmonkey
i am the owner and this is a private repo i just wanted to use version control can you pls tell me the commands i need to do to change the 2 commits to another branch because i am just starting to learn git if i can't i will start from the beginning i am not too far in so i do not think it will make too much of a difference
DougR
DougR
Great place to learn about Git branching: [URL]https://learngitbranching.js.org/[/URL] You can likely learn what you need to know in less than 1 hour. Cheers.
carmonkey
carmonkey
ok will check it out

1-5 of 5

Reply to this discussion

You cannot edit posts or make replies: You should be logged in before you can post.

Post a reply
1804 views