Reputation: 93
I have cloned a git repo locally. I have made a number of commits to master branch and not pushed into remote. In the meantime, others have added to the master of remote. Now I want to keep my commits on remote repo but in a branch that starts at the commit that I initially cloned from. The main reason is to keep the history of my commits, yet not to merge with master. Thanks in advance for any useful ideas.
Upvotes: 0
Views: 70
Reputation: 4709
cjc343's answer, while technically correct, feels incomplete to me. I'd suggest making a local branch for your work and then pushing it. And that way master can track origin/master, and trust me, life is easier when you're doing this.
Assuming you're at HEAD, and your master is still several commits beyond your initial clone point...
git checkout -b new_branch
git push origin new_branch
git checkout master
git reset --hard origin/master
This 1) makes a new local branch, 2) pushes it to the remote repository, 3) switches to master, and 4) resets master to origin/master so you can once again pull other people's work easily.
Upvotes: 1
Reputation: 3765
Assuming your remote is origin
and your local branch is master
and you'd like to push to new_branch
:
git push origin master:new_branch
Upvotes: 5