git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] git pull ignores pull.autostash=true configuration when used with --git-dir and --work-tree flags on a bare repository

From
BLBryan Lee <hi@looping.me>
Date
Jul 15, 2025, 03:26 UTC
Message-ID
<010001980c1ee007-2797fc86-fdf3-46e9-bec9-f8da2c9ebb8d-000000@email.amazonses.com>
What did you do before the bug happened? (Steps to reproduce your issue)

I am using a bare Git repository to manage my dotfiles, following a common pattern where the Git directory is separate from the work tree. Here are the exact steps to reproduce the issue:

1. Create a bare repository and set up the alias:
   $ git init --bare $HOME/.dotfiles
   Initialized empty Git repository in /Users/bryan/.dotfiles/
   $ alias dot='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
2. Add a remote and create initial tracked file:
   $ dot remote add origin git@github.com:username/dotfiles.git
   $ echo "# My dotfiles" > $HOME/README.md
   $ dot add $HOME/README.md
   $ dot commit -m "Initial commit"
   [main (root-commit) abc1234] Initial commit
    1 file changed, 1 insertion(+)
    create mode 100644 README.md
   $ dot push -u origin main
   Branch 'main' set up to track remote branch 'main' from 'origin'.
3. Set global Git configuration for automatic rebasing and stashing:
   $ git config --global pull.rebase true
   $ git config --global pull.autostash true
   Verify the configuration is set:
   $ git config --global pull.rebase
   true
   $ git config --global pull.autostash
   true
4. Simulate a remote change (on another machine or via GitHub web interface):
   - Edit README.md on remote to add a line: "Updated from remote"
   - This creates a divergence between local and remote
5. Make local unstaged changes:
   $ echo "Local change" >> $HOME/.zshrc
   Verify there are unstaged changes:
   $ dot status
   On branch main
   Changes not staged for commit:
     (use "git add <file>..." to update what will be committed)
     (use "git restore <file>..." to discard changes in working directory)
    modified:   .zshrc
   no changes added to commit (use "git add" and/or "git commit -a")
6. Attempt to pull the remote changes:
   $ dot pull
   error: cannot pull with rebase: You have unstaged changes.
   error: Please commit or stash them.
What did you expect to happen? (Expected behavior)
Since I have configured pull.autostash=true globally, I expected Git to:
1. Automatically create a stash of my unstaged changes (the modified
.zshrc file)
2. Pull the remote changes with rebase (as configured by pull.rebase=true)
3. Apply the stash after the pull completes successfully
4. Show output similar to:
   Created autostash: abc2345
   First, rewinding head to replay your work on top of it...
   Fast-forwarded main to origin/main.
   Applied autostash.

This is the behavior I get when using Git in a regular (non-bare) repository with the same configuration.

What happened instead? (Actual behavior)

Git immediately fails with an error message: error: cannot pull with rebase: You have unstaged changes. error: Please commit or stash them.

The command exits with status code 1 and does not perform any stashing or pulling.

What's different between what you expected and what actually happened?

The difference is that Git is not honoring the pull.autostash=true configuration when the repository is accessed using --git-dir and --work-tree flags. The autostash feature is completely ignored, and Git behaves as if pull.autostash=false.

To confirm this is specific to the --git-dir/--work-tree usage pattern, I tested the following workarounds:

1. Explicit --autostash flag works:
   $ dot pull --rebase --autostash
   Created autostash: def3456
   Current branch main is up to date.
   Applied autostash.
2. The same configuration works in a regular repository:
   $ cd /tmp/test-repo
   $ git init
   $ git config pull.rebase true
   $ git config pull.autostash true
   $ echo "test" > file.txt
   $ git add file.txt
   $ git commit -m "test"
   $ echo "change" >> file.txt
   $ git pull origin main  # This would autostash as expected
Additional diagnostic information:
1. The configuration is properly loaded by Git:
   $ dot config --show-origin pull.autostash
   file:/Users/bryan/.config/git/config true
   $ dot config --show-origin pull.rebase
   file:/Users/bryan/.config/git/config true
2. Even setting the configuration directly in the bare repository doesn't help:
   $ dot config pull.autostash true
   $ dot config pull.rebase true
   $ cat $HOME/.dotfiles/config | grep -A2 "\[pull\]"
   [pull]
    rebase = true
    autostash = true
   $ dot pull
   error: cannot pull with rebase: You have unstaged changes.
   error: Please commit or stash them.
3. Using -c flag to override configuration inline also fails:
   $ git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME -c
pull.autostash=true pull
   error: cannot pull with rebase: You have unstaged changes.
   error: Please commit or stash them.
4. GIT_TRACE output shows the pull command is executed but autostash
is not attempted:
   $ GIT_TRACE=1 dot pull 2>&1 | head -5
   11:09:57.474770 git.c:476               trace: built-in: git pull
   error: cannot pull with rebase: You have unstaged changes.
   error: Please commit or stash them.

This appears to be a bug where the autostash functionality is bypassed when Git is invoked with --git-dir and --work-tree flags, possibly because the work tree context is not properly established when the autostash check occurs.

[System Info]
git version:
git version 2.50.1
cpu: arm64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
libcurl: 8.7.1
zlib: 1.2.12
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
uname: Darwin 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:29
PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6030 arm64
compiler info: clang: 17.0.0 (clang-1700.0.13.3)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh
Next: Lidong Yan
Message 1 of 23 in “[BUG] git pull ignores pull.autostash=true configuration when used with --git-dir and --work-tree flags on a bare repository”
  1. Bryan LeeJul 15, 2025
  2. Lidong YanJul 15, 2025
  3. Bryan LeeJul 15, 2025
  4. Bryan LeeJul 15, 2025
  5. Lidong YanJul 15, 2025
  6. Junio C HamanoJul 15, 2025
  7. Lidong YanJul 16, 2025
  8. Johannes SixtJul 16, 2025
  9. Lidong YanJul 16, 2025
  10. Junio C HamanoJul 16, 2025
  11. pull: add pull.autoStash config optionLidong Yan, Jul 17, 2025
  12. Eric SunshineJul 17, 2025
  13. Lidong YanJul 17, 2025
  14. Junio C HamanoJul 17, 2025
  15. Lidong YanJul 17, 2025
  16. Junio C HamanoJul 17, 2025
  17. Junio C HamanoJul 17, 2025
  18. pull: add pull.autoStash config optionLidong Yan, Jul 18, 2025
  19. Junio C HamanoJul 18, 2025
  20. Lidong YanJul 19, 2025
  21. pull: add pull.autoStash config optionLidong Yan, Jul 20, 2025
  22. Junio C HamanoJul 21, 2025
  23. Ben KnobleJul 17, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.