user3378283
user3378283

Reputation: 307

how to perform git operations with specified username/password?

I want to run script on a CI server which will automatically remove old branches from git repository. I have to pass git's username/password as parameters to this script because server is shared between different teams, so I can't, for example, store ssh key on a server. I can clone repository with provided credentials git clone https://username:[email protected]/username/repository.git. But I can't perform any other operations, for example, git push origin --delete branch_name - the promt will ask for password. Is there a way to provide credentials for git operation in my case via script?

Upvotes: 0

Views: 154

Answers (1)

Nayagam
Nayagam

Reputation: 1875

The Prompt will never ask for the password when you clone a repository with the following command.

git clone https://username:[email protected]/username/repository.git

please make sure your username and password are set in origin keyword.

git remote -v

origin  https://username:[email protected]/username/repository.git (fetch)
origin  https://username:[email protected]/username/repository.git (push)

If it is not present then try to change url

git remote set-url origin https://username:[email protected]/username/repository.git 

After that it won't ask for password

git push origin --delete branch_name

Upvotes: 1

Related Questions