git - create a new branch from local copy and then merge it with existing branch

169 views Asked by At

Being a git newbie, I have messed up a little bit in the way I handled a new development and I do not succeed in resolving this properly.

I have a master branch. I made a local copy of this master branch on my desktop computer and then I removed the hidden .git folder (don't ask me why). I did quite some work on this local copy and I also updated the master branch to resolve some bugs and pushed the changes.

Now I want to create a new branch new_version for this new branch on which I worked locally. Then I want to merge the modifications from master into new_version.

How can I do that ?

In my local branch I tried the following which ended up in a total mess:

git init
git pull my_repo master

So I reverted to the initital state where this local new branch was not even a git repository.

2

There are 2 answers

2
David Deutsch On BEST ANSWER

Assuming you mean that you made a local copy of the root folder and worked on it (without the .git directory), simply go back to the original directory and make sure you are up to date with git pull. Then, take your local copy and copy it over the original directory (making sure, again, that there is no .git directory in your copy). Then, simply commit your changes with git add . and git commit.

0
Andreas Wederbrand On

First create a branch from the point where you made a copy of your master branch

git branch <branch name> <sha1>

Then copy all of your files from your copy into the working copy, all your changes should now show as diffs.

git commit -am'new stuff made'

Commit your changes and then rebase from master to have all recent changes applied

git rebase master