Flipper Flipper - 1 year ago 113
Git Question

Git new branch from working branch with commits only from working branch

I've cloned repo and I have created new branch from master called working-branch. I was just doing local commits, I did not push anything yet. I want to actually first create new branch and after that push that branch to remote, but I want to take only commits history from working-branch. How to do that? I was reading about

git rebase
but I do not know if it's right thing.

Answer Source

That would be a new repo. A git repository contains all the comits from the start. But remember that when you push a new branch you are not copying all the previous commits, but simply pushing the ones which are new since you branched out and a reference to the last commit in that tree. This is the beauty of git branches, they are very lightweight because the basically are one line in a file containing the branch name and a commit id.


If what you want is to add the commits from your working branch to master you could do the following:

git checkout working-branch 
git rebase master 
git checkout master 
git merge working-branch 
git push origin master 

This will add your new commits to the tip of the master branch after resolving possible conflicts on your working branch.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download