简体   繁体   中英

How do i clone work from the master branch to a new one?

I've been working on the master branch. Now i want to pull all the work to a new branch i just created to continue working there.

Im new on git, and the idea is to work on a branch and just merge it on master until my code pass(im on school). But i already started and had made lots of progress that i dont want to lose.

I already git checkout but it just returns me a blank readme.

If the last few commits done on master should have been done on a feature branch instead, you can:

  • create a feature branch
  • reset master to where it should have been

That is:

m--m--m--f--f--f (master)

git checkout -b feature
git push -u origin feature

m--m--m--f--f--f (master, feature)

git checkout master
git reset --hard @~3 # make sure you don't have any pending modification
                     # this reset 3 commits back: adapt to your case

If you had already pushed master, you might need to git push --force .
If you are several working on the same repository, do communicate first before force pushing any branch.

From your description I can imagine that you're working on the master branch, but it seems that you haven't added changes and you haven't created any commit ( I guest only ) In that case, you can just create a new branch

git checkout -b new_branch_name

In case you committed your work into commits in master branch and already pushed it to Github (ignore below commands if you haven't), you can back to master branch reverse it

git checkout master 
git reset --hard HEAD~HERE_NUMBER_OF_YOUR_NEW_COMMITS
git push origin master -f
git checkout new_branch_name #To continue work on new branch (with all your new works remained)

Then, commit changes ( this should be repeated many times when you have completed sth

git add .
git commit -m "I created new feature"
git push new_branch_name

And then, from Github, you can create a pull request so your tutor / teammate can review

You just need to create new branch from master branch. Everything from master branch will be available on new branch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM