Can I fetch a stash from a remote repo into a local branch?

时光怂恿深爱的人放手 提交于 2019-11-27 09:02:59
sehe

Update: A direct answer to the original poster's question is:

git send-pack ./ 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0:refs/heads/tempbranch

'tempbranch' will be at the latest stash (stash@{0}) from the remote. Unfortunately I don't think the reflog is fetched from remote branches, so there is no way to get at the other stashes, unless you have access to the source repo.

Scripting it: I posted a more comprehensive 'scripted' solution over at the mentioned question

Is it possible to push a git stash to a remote repository?

Also, as I discovered in the meantime, git-send-pack can be instrumental if you have access to the source repo:

git send-pack ../myworkingfolder/ stash@{0}:refs/heads/collegue_stash

Yes, you can, partially. The stash is just another ref. You can fetch refs which are not heads (branches) by specifying a refspec with the full ref path.

git fetch some-remote +refs/stash:refs/remotes/some-remote/stash
git stash apply some-remote/stash

You can configure this up to fetch the stash when you run an ordinary fetch, too:

git config --add remote.some-remote.fetch +refs/stash:refs/remotes/some-remote/stash
git fetch some-remote
git stash apply some-remote/stash

But this will fail if there is no stash with a "Invalid refspec" as the ref doesn't exist, so you're probably better off doing it on demand. You could set up an alias like:

cat > /usr/local/bin/git-fetch-stash
git fetch --verbose "$1" +refs/stash:refs/remotes/"$1"/stash 
^D
chmod +x /usr/local/bin/git-fetch-stash

git fetch-stash some-remote

The caveat is that you cannot fetch multiple stashes. These are stored as entries in the reflog, and you cannot fetch a remote's reflog.

naven87

You can't but this provides you an alternate path. is-it-possible-to-push-a-git-stash-to-a-remote-repository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!