开发者

git push, dont push all local commits

开发者 https://www.devze.com 2023-04-12 10:46 出处:网络
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 al开发者_如何学编程l commits d

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 al开发者_如何学编程l 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号