Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Git push #191

Merged
merged 1 commit into from
Mar 12, 2021
Merged

Improve Git push #191

merged 1 commit into from
Mar 12, 2021

Conversation

driesvints
Copy link
Member

After talking to some of my GitHub contacts they gave me a tip for a safer way to do a git push after creating the GitHub repo. Doing so will allow us to remove the note about the gh_protocol in the docs as it won't matter anymore what protocol you use.

@taylorotwell taylorotwell merged commit 41543d5 into master Mar 12, 2021
@taylorotwell taylorotwell deleted the improve-git-push branch March 12, 2021 13:52
@owenvoke
Copy link

Bear in mind, this won't work on Windows unless using WSL.

driesvints added a commit that referenced this pull request Mar 16, 2021
driesvints added a commit that referenced this pull request Mar 16, 2021
@driesvints
Copy link
Member Author

Thanks @owenvoke for the heads up. Reverting this.

@mislav
Copy link

mislav commented Mar 17, 2021

@owenvoke How does this break on Windows outside of WSL?

I've just tried this in PowerShell:

PS C:\Users\mislav\gh-cli> $env:GIT_TERMINAL_PROMPT=0
PS C:\Users\mislav\gh-cli> $env:GIT_TRACE=1
PS C:\Users\mislav\gh-cli> git -c credential.helper= -c credential.helper='!gh auth git-credential' push
22:27:41.451926 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
22:27:41.451926 git.c:447               trace: built-in: git push
22:27:41.451926 run-command.c:667       trace: run_command: GIT_DIR=.git git remote-https origin https://github.com/cli/cli
22:27:41.467552 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
22:27:41.467552 git.c:734               trace: exec: git-remote-https origin https://github.com/cli/cli
22:27:41.467552 run-command.c:667       trace: run_command: git-remote-https origin https://github.com/cli/cli
22:27:41.483174 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
22:27:41.733443 run-command.c:667       trace: run_command: 'gh auth git-credential get'
22:27:42.021091 run-command.c:667       trace: run_command: 'gh auth git-credential store'
Everything up-to-date

You can see that gh is successfully used as a credential store for git operations.

Note:

  • fresh Windows 10 install
  • no WSL present
  • Git for Windows installed
  • GitHub CLI installed

@owenvoke
Copy link

owenvoke commented Mar 18, 2021

It works if you use $Env: because that's a PowerShell directive. If you run the full command directly, it will fail.

GIT_TERMINAL_PROMPT=0 git -c credential.helper= -c credential.helper='!gh auth git-credential' push -q -u origin main

The issue isn't so much the following command, but the fact that Windows tries to run GIT_TERMINAL_PROMPT as an executable.

@driesvints
Copy link
Member Author

Is there any way we can write the line so it can work on every Windows environment? I have zero knowledge of working with Windows so would be cool if anyone could paste that here or send in a PR.

@mislav
Copy link

mislav commented Mar 19, 2021

I'm not familiar with Symfony, but it looks like environment variables should be passed as a separate argument: https://symfony.com/doc/current/components/process.html#setting-environment-variables-for-processes

With that syntax, processes should likely work across platforms.

@driesvints
Copy link
Member Author

@mislav thank you!

@mislav @owenvoke does #196 look good to you?

@owenvoke
Copy link

Looks perfect, I'll test it in a bit once I'm off lunch. 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants