Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute git pull with username and password

Tags:

git

bitbucket

Is there way to put username and password in the command with git pull, to avoid password message. for example

git pull -u ahmeditman -p 123456  #this example to explain . 

It is okay to use

git pull http://ahmeditmna:[email protected] 

But it will pull from Master Branch, but if i need to pull from dev Branch ?

like image 554
AhmedMItman Avatar asked Oct 30 '18 12:10

AhmedMItman


People also ask

Why is git pull asking for password?

If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository. Using an HTTPS remote URL has some advantages compared with using SSH.

How do I bypass the username and password in git clone?

Entering Git Username and Password in Remote URL To prevent Git from asking for your username and password, you can enter the login credentials in the URL as shown. The main drawback of this method that your username and password will be saved in the command in the Shell history file.


2 Answers

It is okay to use

git pull http://ahmeditmna:[email protected]

I think you mean git clone http://ahmeditmna:[email protected]


Technically speaking, yes. http://username:password@domain/path is a valid URL part of HTTP(S) protocol.

But is that safe or should you do it? No.

Well first, it's better to use HTTPS, if you are pushing / pulling from a public repository it won't be a problem since data is already public, but if it's a private repository your data could be read by an attacker.

But the more important part is anyone having access to the copy of your repository would be able to read your credentials. Just try it (I took the first Python related repository for this example..):

cd /tmp/
git clone 'https://username:[email protected]/mshibly/python-examples-from-intro-to-python-course.git'
cd python-examples-from-intro-to-python-course/
git remote -v

git remote -v list repository's remotes URL, let's see:

origin   https://username:[email protected]/mshibly/python-examples-from-intro-to-python-course.git (fetch)
origin   https://username:[email protected]/mshibly/python-examples-from-intro-to-python-course.git (push)

As you can see, your credentials are here, waiting to be read.

And that's even worst if you use this on a server since depending on your general configuration you can find your credentials in logs. Not speaking about the fact you may end by scripting this and have your credentials into a script you may commit and / or store on someone's else server.

The point here is there are not good reasons to do this, but there a plenty of good reasons to not.

No, it's not ok to do this. I advise you to spend some hours learning how SSH works and configuring your OS.

like image 134
Arount Avatar answered Sep 17 '22 07:09

Arount


If you override the remote origin URL (git config remote.origin.url) to http://ahmeditmna:[email protected], like:

git remote set-url origin http://ahmeditmna:[email protected]

Pull will work without prompting for password on any kind of branch.

like image 32
Bence Kaulics Avatar answered Sep 21 '22 07:09

Bence Kaulics