3

git fetch --quiet &>/dev/null & is still writing to stdout asking for the username. Is there any workaround to archive this.

Edit: Adding details I have a custom script to display git status(modified version of bash-git-prompt) The script runs the above command in the background.

The problem with the above command is when I cd to a private repo for which I authenticate using HTTP authentication.(I can't save username or password in git URL for obvious reasons.) I get an annoying message while in mid of typing command git fetch writing to stdout

What I need is that is there any way to stop this. &> is not working because it git credential who is printing to stdout not git as @torek told ref.

Kshitij
  • 353
  • 3
  • 10
  • Is the repo private? – Riccardo Petraglia Apr 10 '17 at 11:46
  • yes the problem is for private repo. – Kshitij Apr 10 '17 at 11:49
  • 4
    Git *isn't*. It's a credential helper of some sort that's asking for credentials. If the repository requires some kind of authentication to use, you must provide that authentication somehow. The details vary based on both OS (Windows, Mac, Linux all differ) and transport (ssh vs https). – torek Apr 10 '17 at 12:28
  • As @torek said. Probably the best/easiest way is to set up the ssh access from github/bitbucket/somethingelse settings. Then you will not need anymore to type in username and password each time you want to fetch/pull something – Riccardo Petraglia Apr 10 '17 at 12:58
  • @RiccardoPetraglia that would work no doubt but what I need is that it also work for the case where I don't have push/pull permission. – Kshitij Apr 10 '17 at 13:24
  • try specifying the address as `https://username:password@github.com/username/repository.git` (Credits: http://stackoverflow.com/questions/10054318/how-to-provide-username-and-password-when-run-git-clone-gitremote-git) Of course you will have to write your password in a plain file, which is not the best thing to do.... The same link also shows an alternative method based on ssh... – Riccardo Petraglia Apr 10 '17 at 14:52
  • There is no such thing as "pull permisson": pull = fetch + second-step. Fetch and clone are the same thing so if you do not have fetch/clone permission, you do not have a clone in the first place. – torek Apr 10 '17 at 17:28
  • @torek my bad, I just want to know if there is a way to not print on stdout while running that command. – Kshitij Apr 10 '17 at 17:31
  • On MacOS, the system will use identities taken from your keychain. You are on MacOS, right? :-) Seriously, again, it's OS-dependent. If the remote server allows `git://` access, that particular transport is always password-less; and `ssh://` access uses passwords or access tokens that can be redirected to various agents and/or recovered from files, so that can also be automated. – torek Apr 10 '17 at 17:35
  • @torek Ubuntu. I am using [gitcredentials](https://git-scm.com/docs/gitcredentials) but it expires after some time then there are annoying prompt asking for username and that too in between me typing a command. That what's annoying me. – Kshitij Apr 10 '17 at 17:39
  • This is the kind of detail that should go in the question. Anyway, follow the link from those docs to the `git-credential-cache` entry and see the `--timeout` option; or you can use `git-credential-store` to store these credentials in a file, although the file itself must then be secure to avoid leaking username and password. – torek Apr 10 '17 at 17:43

1 Answers1

0

The 2021 solution would be to use Microsoft GCM (Git-Credential-Manager-Core), in order to cache the credentials.

It is a cross-plateform solution, which also works on Linux/Ubuntu, provided you add a credential store.

And make sure to use Git 2.34 (Q4 2021), where "git fetch --quiet"(man) includes an optimization to avoid useless computation of info that will never be displayed.

See commit f6bb64d (30 Aug 2021) by Patrick Steinhardt (pks-t).
(Merged by Junio C Hamano -- gitster -- in commit 87d4aed, 10 Sep 2021)

fetch: skip formatting updated refs with --quiet

Signed-off-by: Patrick Steinhardt

When fetching, Git will by default print a list of all updated refs in a nicely formatted table.
In order to come up with this table, Git needs to iterate refs twice: first to determine the maximum column width, and a second time to actually format these changed refs.

While this table will not be printed in case the user passes --quiet, we still go out of our way and do all these steps.
In fact, we even do more work compared to not passing --quiet: without the flag, we will skip all references in the column width computation which have not been updated, but if it is set we will now compute widths for all refs.

Fix this issue by completely skipping both preparation of the format and formatting data for display in case the user passes --quiet, improving performance especially with many refs.
The following benchmark shows a nice speedup for a quiet mirror-fetch in a repository with 2.3M refs:

Benchmark #1: HEAD~: git-fetch
  Time (mean ± σ):     26.929 s ±  0.145 s    [User: 24.194 s, System: 4.656 s]
  Range (min … max):   26.692 s … 27.068 s    5 runs

Benchmark #2: HEAD: git-fetch
  Time (mean ± σ):     25.189 s ±  0.094 s    [User: 22.556 s, System: 4.606 s]
  Range (min … max):   25.070 s … 25.314 s    5 runs

Summary
  'HEAD: git-fetch' ran
    1.07 ± 0.01 times faster than 'HEAD~: git-fetch'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250