with Git you can commit locally and push the commit to a central Git server once everything ready is or if you are back online. But what if you made a lot of commits and you just want to share some commits, but not all.
Let’s say you have made following commits:
- 74b6625 commit 1
- a8a9b00 commit 2
- 1e6cf4b commit 3
and you want to push the change set 74b6625. Following trick helps:
First you need to reorder your commit. The commit(s) you want to push have to be push down.
git rebase -i
will open editor and showing following lines
pick e418ad1 comment 1 pick a8a9b00 comment 2 pick 1e6cf4b comment 3
just reorder the line so commit 74b6625 (commit 1) is after 1e6cf4b (commit 3).
pick a8a9b00 comment 2 pick 1e6cf4b comment 3 pick e418ad1 comment 1
after saving the changes, git reorder the commits according the changes you just made.
To push, just run following command:
git push origin e418ad19c1700b35ee484d84db2ee8559137c6f8:master
if you use the SHA-1 of commit 3, then commit 1 and commit 3 will be pushed.
Happy pushing 🙂