AwesomeGuy
AwesomeGuy

Reputation: 1089

Git commit only for me

I was wondering, is there an option in git for me to commit my changes so I can continue working on my other PC/laptop without anyone else being able to pull?

Example, I'm working on a feature in one of the branches (notice that I don't want to create a new branch), on my desktop pc and since I didn't finish it and I have to go some place for a couple of days, I want to continue working on my laptop, but I don't want others to be able to pull since it isn't finished it can cause some unwanted behaviour.

So basically, to commit only for myself and later when I finish I can push to everyone else on the project.

Upvotes: 0

Views: 1491

Answers (1)

Jan Hudec
Jan Hudec

Reputation: 76236

but I don't want others to be able to pull since it isn't finished it can cause some unwanted behaviour.

The project is otherwise public, isn't it? So the commits will be visible anyway when you eventually publish next version, won't they? So they can't contain anything illegal or otherwise problematic, can they? The only thing they can is be broken state…

Therefore, if somebody wants to shoot themselves in the foot by explicitly pulling code from a branch called for-test or experiment, it's their problem, not yours.

Therefore, do push to a branch. Name it test (or for-test or experiment or something like that, but nothing fancy, please). And I mean those suggestions very literally; the branches will only exist until you test on the other machine!

Pushing to such branch is trivial:

git push origin HEAD:test

Then on the other machine, you just pull it:

git pull origin test

and test it and fix it. And when you are done and merge it to the actual target, you just delete the test branch again:

git branch -d test

gets rid of the local branch, and

git push -d origin test

gets rid of the one on github.

Yes, you can also set up remote for direct push from one computer to the other. But that requires to have them both running and on the same network and have ssh connection or something. And then you'll want to ask somebody else to also test it and you'll need the test branch anyway.

So do make a test branch; branches are cheap.

This is a big difference compared to traditional centralized version control systems where commits belonged to branches. There you had to think carefully before creating one, because they were there to stay forever. But in distributed systems branches are just labels for revisions that can be easily added to already existing revisions and easily deleted when they are no longer needed. Once you get used to it, you'll find branches are much more useful in git and other distributed systems then they used to be in the older systems.

Upvotes: 3

Related Questions