3

I have 2 computers, one in office and one in home, we use git for version control, and I want to use it to sync my works, which usually are not even ready for a small commit, so I don't want leave a commit message in our gitlab server. The first idea come to my mind is git stash, can I git stash my current work? And push the stash to the remote server. Then pull the git stash in another computer and restore the work by git pop. Something like:

This is not exactly steps, but you can get my idea.

Step 1: In Computer-Office

git stash
git push (the stash contents)

Step 2: In Computer-Home

git pull # pull the stash contents
git stash pop # pop the difference I already git stash in the Computer-office
# some modified, new files and delete some files.
git stash
git push (the stash contents)

Step 3: In Computer-Office

git pull # pull new stash content at home
git commit # the final commit
Liao Zhuodi
  • 3,144
  • 5
  • 26
  • 46

2 Answers2

2

Stash is meant for local storage, there's no way you can push that to remote unless you use other tools (dropbox etc) to transfer the .git files.

One approach is to put ur repo in dropbox, then sync uncommitted changes using dropbox.

If not you simply have to commit and push to remote, then rebase to squash the minor commits into a single one, then force push to remote so that your commit history remains neat.

You can also do git reset --soft HEAD~to remove the last commit from history but keep the changes in your local repo, which is pretty much what you are trying to accomplish with stash.

Roy Wang
  • 11,112
  • 2
  • 21
  • 42
1

As mentioned in "Is git stash stack pushed to the remote repo?", a stash cannot be pushed.

So creating a commit in a new "wip" (work-in-progress) branch, and pushing that branch is the surest way to save one's work to the remote server.

Elsewhere, you can merge or cherry-pick or rebase that branch onto a legacy one.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250