Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I move the contents of my master branch to a new Git branch?

Tags:

git

I've been making some vast changes on the master branch of my Git repository. I'm pretty new to Git and so I'm wondering:

How can I move my current master branch to a new branch and recreate my master branch from scratch for a particular folder of files?

As an example, I have another folder, like new_stuff, that contains the new files to be added to the master branch, and that old master is a new branch named old_master.

like image 813
Spyros Avatar asked Jul 05 '11 03:07

Spyros


People also ask

How do I move to a new branch?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


2 Answers

Within the directory of the repository, in the command line type the following:

git branch -m master old_master git branch master 

This should be enough :)

like image 79
Tadeck Avatar answered Sep 25 '22 22:09

Tadeck


Use git branch -m master old_master to rename master to something else. Then do something like git checkout -b master HEAD~2 to create the new master as per your needs ( in this case till the 2nd commit from previous HEAD ) Now add / replace the folder new_stuff and commit in master

like image 45
manojlds Avatar answered Sep 24 '22 22:09

manojlds