Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push, dont push all local commits

Tags:

git

push

I'm new to git and testing it out right now. On my local machine I do frequent commits. At intervals I want to push the code to a central repo. At this moment I publish all commits done. When I work alone this is not a big issue, but when I work with multiple dev's on a project this gets chaotic. Meanwhile I would like to have all local commits preserved on my local machine, just in case.

Is this a good way to work with git? Is this possible? Or am I thinking the wrong way?

like image 440
Patrick Avatar asked Oct 12 '11 23:10

Patrick


2 Answers

One way you could deal with this is to make yourself a personal development branch in your local repository. It's just a regular branch, nothing special, but commits on the branch will not get pushed to the central repository when you run git push. When you're ready to share your changes, merge the commits from your personal branch into the master branch and then you can push them to the central repository.

A variation on this would be to start a new branch for each logical feature you work on, so that you would have many small personal development branches instead of one big one. Then you can delete the feature branches once you merge them into the master branch.

like image 132
David Z Avatar answered Sep 30 '22 13:09

David Z


The Git workflow encourages you to clean up your local (early-and-often) commits into a logical sequence of commits that take the eventual reader step-by-step through the implementation of your new work. This can be done using the git rebase -i feature and other tools. With that, you can reorder, edit, split, and squash commits as needed to make it all look nice. Then push that set of commits to the server, and of course keep it locally too.

This workflow is by no means required. You can push up all your detailed commits to the server (but you claim that gets "chaotic"), or you can squash your work into a single commit and push that up. What you cannot reasonably do though, is push one commit to the server while keeping another set locally.

like image 44
Greg Hewgill Avatar answered Sep 30 '22 14:09

Greg Hewgill