Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share unfinished work (uncommited and new files) via Git

Tags:

git

I do my work from three different workstations. I would like to be able to leave a workstation in the middle of a coding sessions and resume this work later on another workstation. Given that the code is shared via a remote git repo, I would like to use git to share this unfinished work.

In practical terms, unfinished work means

  • there are changed files,
  • there are new untracked files,
  • there are deleted files.

Most of the times these changes are temporary: not all the changes and most of the untracked files will finish in the final commit. An example of untracked file is a test file duplicated with 20 slightly different modifications for test purposes; I care about all these files only while I'm working on a certain problem and I do not want to lose time regenerating them when switching to another workstation.

I have seen other questions and solutions that use a branch to push these changes: while I am OK with this, there is the problem that these branches will be rewritten every time, requiring a git push --force (I do not like --force much) or allowing them to become very messy over the time.

What I would like to have is a simple command or git alias that allow me to store the current state of the work directory without "messing too much" with the git history. There must be a companion simple command or git alias that allow me to download these temporary changes from the other workstations.

like image 780
gioele Avatar asked Apr 19 '12 10:04

gioele


2 Answers

Use git stash to save your changes to a file.

git stash
git stash show -p > myPatchFile

On the other computer apply them

git apply myPatchFile
like image 182
Pascal_dher Avatar answered Sep 24 '22 06:09

Pascal_dher


  1. You could use git add -A to remove deleted and add new files. Then commit it into a branch named say my_current_work. Exchange it via remote repo using --force. You could share a new one remote which is only for you to make the main repo cleaner. Or if you have a network link between workstations you could push/pull changes directly between them. Before merging your work into the master branch you do rebase -i to clean up commit history.

  2. As alternative to remote repo for exchanging you could send patches via e-mail (git-send-email).

like image 38
kan Avatar answered Sep 24 '22 06:09

kan