Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Move all files from remote master to branch

I made a mistake starting a new repo by pushing to remote master. I want to take those changes and put them in a branch and have none of them in master.

I tried following this Move all files from master to another branch in Git but don’t know if it was really doing what I wanted since I also want to remove files from remote master. I want to be able to make a pull request.

Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to move commits from one branch to another, you are looking to cherry-pick, then you can drop the changes on master.

On master do:

git log --pretty=oneline --graph --decorate --abbrev-commit 

This will show all the commits on master. Find the one(s) you want, and copy the commit hash (it’s the 8 chars value you’ll see).
Then checkout your branch and do:

git cherry-pick <commit_hash>

Finally, checkout master and do:

git rebase -i HEAD~<number_of_commits_to_drop>

I’m assuming here your commits on master are the latest. If they are not, you’ll need to increase the <number_of_commits_to_drop> so the ones you want show.
A window will open showing something like pick xxxxxxxx commit_message. Simply replace pick with d for the commits you want to drop, save and exit.

Your new branch now has the new commit(s) and the master branch doesn’t.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading