How to input password to git pull command?

前端 未结 3 1332
面向向阳花
面向向阳花 2021-02-02 12:22

I have written scripts for Windows and Linux to essentially set up a new users workspace with all the git repositories from our server.

I would like the user to enter th

相关标签:
3条回答
  • 2021-02-02 12:53

    I would really recommend to not try and manage that password step, and delegate that (both on Linux and Windows) to git credential helper.
    See:

    • "Git http - securely remember credentials"
    • "How to use git with gnome-keyring integration"

    The user will enter the password only once per session.

    0 讨论(0)
  • 2021-02-02 13:04

    Synopsis:

    git pull "https://<username>:<password>@github.com/<github_account>/<repository_name>.git" <branch_name>
    

    Example:

    git pull "https://admin:12345@github.com/Jet/myProject.git" master
    

    Note: This works for me on a bash script

    0 讨论(0)
  • 2021-02-02 13:05

    Read the remote url from git and then insert the ID and password (PW) to the url might work.

    For example try the following:

    cd ${REPOSITORY_DIR}
    origin=$(git remote get-url origin)
    origin_with_pass=${origin/"//"/"//${USER_ID}:${USER_PW}@"}
    git pull ${origin_with_pass} master
    
    0 讨论(0)
提交回复
热议问题