Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "git push" to private repository with prompt for username and password?

Tags:

git

github

I've cloned my private Github repository onto my CentOS 6 machine (git version 1.7.1). Can I somehow set up my local git repository to always prompt for both username and password when typing in git push?

The same username is not always going to be used.

Private repository

$ cat .git/config 

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://github.com/USER/PRIVATE-REPO.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

When I perform git push right now I get this:

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/Industriromantik/render-linux.git/info/refs
fatal: HTTP request failed

If I execute the following, the push is successful:

git push https://[email protected]/USER/PRIVATE-REPO

...however, I am seeking to just execute git push and get prompted for both username and password, if at all possible.

like image 560
fredrik Avatar asked Nov 10 '22 01:11

fredrik


1 Answers

Clone the repository using https://

$ git clone https://github.com/user/private-repo.git/

Since (it seems that) https connections don't cache the password (nor the username, unless you give it in the URL), git will always ask you for the password (and the username):

$ git push
Username for 'https://github.com': USER
Password for 'https://[email protected]': ****
$
like image 106
umläute Avatar answered Nov 15 '22 05:11

umläute