-3

I need to implement the "git pull origin Branchname" without prompting the username and password using the shell script.

git pull origin Branchname

  • look here: https://stackoverflow.com/questions/11506124/how-to-enter-command-with-password-for-git-pull – Dan Chirita May 31 '22 at 07:50
  • 1
    Keep in mind that if Gitlab requires username and password, but you do not want to type them, then you have to write them down somewhere, and suddenly the clear-text password exists not only in your brain, but also in machine readable form on your computer. That is a security flaw. – j6t May 31 '22 at 08:00
  • @j6t yes...but i added the one file in credential.helper but,still it asking username and password – rakesh ricky May 31 '22 at 08:52
  • This has nothing to do with the password issue, but: You should generally *avoid* `git pull` in scripts: it runs `git fetch`, then it runs a second (user configurable!) Git command. Scripts usually should not depend on user configuration. (If they *should*, that's when you want `git pull` after all...) So usually a script should run `git fetch`, then run `git merge`. – torek May 31 '22 at 09:08
  • even i use git fetch,but still it is asking username and password – rakesh ricky May 31 '22 at 10:18

1 Answers1

1

You have two options:

  1. Clone your project using SSH.

    • I don't think you want this because you asked for a username and password. So I'll ignore it.
  2. Clone your project with HTTPS setting the username and password in the URL itself.

    • EX: https://username:password@gitlab.com/my-project
    • If you already cloned the project, you still can edit the URL by: git remote set-url origin https://username:password@gitlab.com/my-project and you cab check your change by git remote -v
raedshari
  • 403
  • 5
  • 16
  • i cant share the my username and password in https,as my whole team uses it. – rakesh ricky May 31 '22 at 08:50
  • 1
    Then create an access token for this as I suggested. Look here on how to create one: https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html#project-access-tokens – raedshari May 31 '22 at 09:39