Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is a question about a best practice. It's probably simple but I'm still fairly new with Git, and I'd like to get good habits for things I do frequently.

The situation is the following. I have two computers CompA and CompB, and a remote repository (on Bitbucket). Let's say I work on a unique branch.

I need to make a big change on a file. I start from Computer A, but I do not have time to finish, and will need to carry on my work on Computer B. I'd like to make available to Computer B the changes already made on Computer A.

I usually do it by committing the changes as they are, pushing to remote repo, then pulling them to Computer B. However, this creates a commit which is not a full self-sufficient set of changes.

If possible I would like to have only one commit with the final set of changes. At least in the remote repo, if possible, also in the local repos of computers A and B.

What is the cleanest way to do this?

share|improve this question
    
Should this go to Stack Overflow? –  Peutch May 11 '12 at 9:01
add comment

1 Answer

up vote 0 down vote accepted

Big changes probably are best made on a separate branch, as it is very easy to create one in Git. Commit as much as you want, push the branch to BitBucket, pull it on computer B... You can use git rebase --interactive to squash commits together before merging them to the master branch.

[master] $ git checkout -b fixXYZ
[fixXYZ] $ hack hack hack
[fixXYZ] $ git commit -m "Fixed some part"
[fixXYZ] $ hack hack
[fixXYZ] $ git commit -m "Fixed another part"
[fixXYZ] $ git push -u origin fixXYZ

Later, anytime before merging to master:

[master] $ git checkout fixsomething
[fixXYZ] $ git rebase -i master

(Although it is not necessary to squash everything into a single commit – sometimes it is easier to read a log of several smaller commits.)

share|improve this answer
    
Thanks! What if not's big enough to warrant a whole branch? By big I meant something long enough that I may have to switch computers in the middle. –  Peutch May 11 '12 at 15:55
    
@Peutch: Branches in Git are very cheap to create and use, there's no real reason to avoid them. If you do not know how long will something take, you can create a branch anytime, even just before leaving to another PC, too -- it is not necessary to do it at the very beginning. –  grawity May 11 '12 at 16:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.