# How to provide authentication along with git command itself ?

7 messages from 2011-07-14 to 2011-07-14. Participants: J. Bakshi, Carlos Martín Nieto, Jon Seymour, Jonathan Nieder.
Thread: https://gitlist.dev/t/27813

## J. Bakshi, 2011-07-14 10:45

Subject: How to provide authentication along with git command itself ?
Message-ID: <20110714161508.2378c155@shiva.selfip.org>
URL: https://gitlist.dev/e/20110714161508.2378c155%40shiva.selfip.org

```
Hello list,

During git push or fetch over http , I need to provide username and password every time, as protected by apache htpasswd file. How can I provide the same along with git command ? Or something so that It save the authentication info somewhere within .git 

Thanks

```

## Carlos Martín Nieto, 2011-07-14 10:50

Subject: Re: How to provide authentication along with git command itself ?
Message-ID: <1310640646.18730.10.camel@bee.lab.cmartin.tk>
URL: https://gitlist.dev/e/1310640646.18730.10.camel%40bee.lab.cmartin.tk
In-Reply-To: <20110714161508.2378c155@shiva.selfip.org>

```
On Thu, 2011-07-14 at 16:15 +0530, J. Bakshi wrote:
> Hello list,
> 
> During git push or fetch over http , I need to provide username and
> password every time, as protected by apache htpasswd file. How can I
> provide the same along with git command ? Or something so that It save
> the authentication info somewhere within .git 

The http transport uses the ~/.netrc file to get its authentication
data.  `man netrc` will tell you about the syntax; for git, you need the
'machine', 'login' and 'password' fields.

Cheers,
   cmn

```

## Jon Seymour, 2011-07-14 10:53

Subject: Re: How to provide authentication along with git command itself ?
Message-ID: <CAH3AnrqR=xMa6KYWBmybXdudo8C8FoeioCs2PgOVZezAE5BWiw@mail.gmail.com>
URL: https://gitlist.dev/e/CAH3AnrqR%3DxMa6KYWBmybXdudo8C8FoeioCs2PgOVZezAE5BWiw%40mail.gmail.com
In-Reply-To: <20110714161508.2378c155@shiva.selfip.org>

```
On Thu, Jul 14, 2011 at 8:45 PM, J. Bakshi <joydeep@infoservices.in> wrote:
> Hello list,
>
> During git push or fetch over http , I need to provide username and password every time, as protected by apache htpasswd file. How can I provide the same along with git command ? Or something so that It save the authentication info somewhere within .git
>
> Thanks

You probably want to create the client setup section of this:

    http://kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt

Personally, I prefer to use an ssh hosted repository in such cases,
then use an ssh-agent to cache an SSH private key.

jon.

```

## J. Bakshi, 2011-07-14 10:59

Subject: Re: How to provide authentication along with git command itself ?
Message-ID: <20110714162953.36347b76@shiva.selfip.org>
URL: https://gitlist.dev/e/20110714162953.36347b76%40shiva.selfip.org
In-Reply-To: <1310640646.18730.10.camel@bee.lab.cmartin.tk>

```
On Thu, 14 Jul 2011 12:50:46 +0200
Carlos Martín Nieto <cmn@elego.de> wrote:

> On Thu, 2011-07-14 at 16:15 +0530, J. Bakshi wrote:
> > Hello list,
> > 
> > During git push or fetch over http , I need to provide username and
> > password every time, as protected by apache htpasswd file. How can I
> > provide the same along with git command ? Or something so that It save
> > the authentication info somewhere within .git 
> 
> The http transport uses the ~/.netrc file to get its authentication
> data.  `man netrc` will tell you about the syntax; for git, you need the
> 'machine', 'login' and 'password' fields.
> 
> Cheers,
>    cmn
> 
> 
> 

Thanks for the response. Can I use the same .netrc to store different authentication for different repo ? Is it somehow possible to store the information at the concerned .git of the repo ? I think this will be easier for multiple repos.

```

## J. Bakshi, 2011-07-14 11:01

Subject: Re: How to provide authentication along with git command itself ?
Message-ID: <20110714163149.63bad937@shiva.selfip.org>
URL: https://gitlist.dev/e/20110714163149.63bad937%40shiva.selfip.org
In-Reply-To: <CAH3AnrqR=xMa6KYWBmybXdudo8C8FoeioCs2PgOVZezAE5BWiw@mail.gmail.com>

```
On Thu, 14 Jul 2011 20:53:42 +1000
Jon Seymour <jon.seymour@gmail.com> wrote:

> On Thu, Jul 14, 2011 at 8:45 PM, J. Bakshi <joydeep@infoservices.in> wrote:
> > Hello list,
> >
> > During git push or fetch over http , I need to provide username and password every time, as protected by apache htpasswd file. How can I provide the same along with git command ? Or something so that It save the authentication info somewhere within .git
> >
> > Thanks
> 
> You probably want to create the client setup section of this:
> 
>     http://kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt
> 
> Personally, I prefer to use an ssh hosted repository in such cases,
> then use an ssh-agent to cache an SSH private key.
> 
> jon.

Well, I am using version 1.7, hence not DAV but using git-http-backend 

```

## Carlos Martín Nieto, 2011-07-14 11:12

Subject: Re: How to provide authentication along with git command itself ?
Message-ID: <1310641975.6041.3.camel@centaur.lab.cmartin.tk>
URL: https://gitlist.dev/e/1310641975.6041.3.camel%40centaur.lab.cmartin.tk
In-Reply-To: <20110714162953.36347b76@shiva.selfip.org>

```
On Thu, 2011-07-14 at 16:29 +0530, J. Bakshi wrote:
[...]
> 
> Thanks for the response. Can I use the same .netrc to store different
> authentication for different repo ? Is it somehow possible to store
> the information at the concerned .git of the repo ? I think this will
> be easier for multiple repos.
> 

I'm not sure, but netrc is not specific for any particular protocol. It
assumes that your login and password are the same for several services
on the same computer or set of computers.

It's often less hassle (and more efficient wrt. data transfer) to use
SSH. With gitolite you can give people access to git repositories over
SSH without giving them SSH access to the machine proper.

Cheers,
   cmn

```

## Jonathan Nieder, 2011-07-14 20:02

Subject: Re: How to provide authentication along with git command itself ?
Message-ID: <20110714200244.GA14687@elie>
URL: https://gitlist.dev/e/20110714200244.GA14687%40elie
In-Reply-To: <20110714163149.63bad937@shiva.selfip.org>

```
J. Bakshi wrote:

> Well, I am using version 1.7, hence not DAV but using git-http-backend 

Ah, I forgot to mention the docs for gitolite and http-backend[1].

As for your original question about how to set up or cache credentials,
unfortunately I haven't tried it.  Based on git-push(1), it looks like
the usual

	http://username:pass@domain/path/to/repo

syntax should work if you're passing the full URL on the command line
or if it's okay to store the usernames and passwords in plaintext in
.git/config.

If that's not okay, it also might be possible to hack up something
evil with the GIT_ASKPASS variable.  Some of the patches mentioned in
the recent discussion about password prompts also might be
interesting[2].

Regards,
Jonathan

[1] http://sitaramc.github.com/gitolite/doc/http-backend.html
[2] http://thread.gmane.org/gmane.comp.version-control.git/176522

```
