Say I made several commits and wish to cherry pick which ones I push to the remote repository. How can I do that (in ascii: C1->C2->C3->C4 and I want to push C2 and C4). Will reordering with rebase, resetting, pushing and then resetting work? (C1->C2->C3->C4 => C2->C4->C1->C3 => reset C4 => push => reset C3). Is there a nicer way?
To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.
You may be looking for:
git push origin $commit:$branch
Credit: http://blog.dennisrobinson.name/push-only-one-commit-with-git/
Explanatory notes:
git rebase -i
), so they are in the order you want to push them.$commit
doesn't have to be a sha1. For example, "HEAD~N" would push everything before the last N commits.$branch
(typically "master" or "main") is the branch you push to – the remote branch. It does not have to be the same as a local branch.If the branch does not exist remotely, and you want to create it, it must be prefixed with refs/heads/
(to disambiguate branch from tag):
git push origin $commit:refs/heads/$new_branch
Pro tip: git-revise is a similar but better tool than git rebase (for local commits specifically). For my purposes, as a daily git user, I think it should be obligatory if you use git revise -i
a lot (which is of course quite necessary to produce high quality commits).
If you have your commits on a private branch, you can cherry pick commits from the private branch and apply them to the official branch. At this point you can now push all your commits on the official branch (which is the subset that you previously cherry picked).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With