No announcement yet.

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

  • Filter
  • Time
  • Show
Clear All
new posts

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

    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 edited by carmonkey; 07-14-2020, 05:17 PM.

  • #2
    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.


    • #3
      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
      Last edited by carmonkey; 07-14-2020, 09:18 PM.


      • #4
        Great place to learn about Git branching:
        You can likely learn what you need to know in less than 1 hour. Cheers.


        • #5
          will check it out