简体   繁体   中英

Github pull from specific remote branch without credentials

I'm in the process of building a script in Powershell that pulls a specific branch from a github repo, then uses msbuild to compile the project. The script accesses the directory containing the git executable, and then requests the remote repo. In order to prevent github from prompting me for credentials, I am using the github access token in the git pull request, shown below:

git --git-dir=<pathtorepo>.git --work-tree=<pathtorepo>  pull https://<githubtoken>@github.com/<myusername/<remoterepo>.git

This works, however it only pull from the master branch, event though in a previous powershell statement I've checked out the correct branch. Is there something I can append to the command above to force git to pull from a specific branch?

I am not sure why, but it can happen that with mentioning the repository explicitly instead of origin in the pull command, git is losing track of the branch it needs to pull from. Can you try by explicitly mentioning the refspec in the git pull command? From the docs , git supports

git pull [options] [<repository> [<refspec>…​]]

So, adding the branch name at the end may work, in case it doesn't work with the branch name alone, please also try with: refs/heads/<branchName>

git --git-dir=<pathtorepo>.git --work-tree=<pathtorepo>  pull https://<githubtoken>@github.com/<myusername/<remoterepo>.git <branchName>

Can you try and let me know if it works?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM