how to pass username and password while cloning TFS to git in window powershell - tfs

I want to import TFS repo to git and clone into my local machine and I am using git-tf. Below my code:- git-tf clone http://server:8080/tfs/DefaultCollection $/SampleProject D:\TFSRepoName I want to pass username and password in url , so it automatic clone repo without asking for username and password.

If you don't want to be prompted for credentials every time you run git-tf, you can store your credentials in your GIT configuration for your repository:
$ git config --global git-tf.server.username your-username
$ git config --global git-tf.server.password your-password
Note that your password will be stored in the git configuration file in plain text. Be sure to set the ACLs or file permissions as appropriate to discourage people from reading your password out of your configuration file. Or you can store just the username and you will need to type only your password each time.
Reference : Accessing TFS with git-tf
You can also try to install and Use the Git Credential Manager,
When you connect to a Git repository from your Git client for the
first time, the credential manager will prompt for your credentials.
Once authenticated, the credential manager will create and cache a
personal access token for future connections to the repo. Git
commands that connect to this account will not prompt for user
credentials until the token expires or is revoked through VSTS/TFS.

One way to pass the credential is -
git pull http://username:password#url
Here "url" will be the url you use to clone the repository on tfs.
But this way is not recommended. Instead you should go for credential manager.

I had to use the default windows credential manager (windows 10 comes with this feature).
Control Panel\User Accounts\Credential Manager
Click windows credentials
Add generic credential
git:(tfs url, no trailing slash) ... example: git:http://tfs
username .. example: domain\username
password
save
Next time you use git for this url your saved credentials will be used

Related

How do I authorize a Jenkins Job to use NuGet on Azure DevOps

In my organization we have some Jenkins jobs building packages and pushing the packages to a private feed on Azure DevOps.
This has been running for years.
The build machine has Credential Manager Core running, enabling the job perform Git operations like tagging and updating submodules on same Azure DevOps orhanisation.
I suppose Credential Manager Core has also been used by Nuget Push.
Every time the Personal Access Token in %AppData%\Nuget\Nuget.Config expired, we created a new PAT for the AD user running the Jenkins service and updated NuGet.Config with:
nuget sources Update -Name <feedname> -UserName <user> -Password <PAT>
Since a few weeks now, the jobs started failing, and the Jenkins log shows:
C:\Users\<user>\.nuget\packages\nuget.commandline\5.8.0\tools\NuGet.exe push C:\Jenkins\workspace\<buildjob>\Deploy\MyPackage.1.0.17.nupkg -ApiKey [hidden] -Source \<feedname>
Pushing MyPackage.1.0.17.nupkg to 'https://pkgs.dev.azure.com/\<organization>/_packaging/\<some GUID>/nuget/v2/'...
PUT https://pkgs.dev.azure.com/<organization>/_packaging/\<some GUID>/nuget/v2/
MSBuild auto-detection: using msbuild version '17.3.1.41501' from 'C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\bin'.
Using credentials from config. UserName: ****
[CredentialProvider]Using the ADAL UI flow for uri https://pkgs.dev.azure.com/<organization>/_packaging/<feedname>/nuget/v3/index.json. User sign-in required in a pop-up authentication window.
[CredentialProvider]DeviceFlow: https://pkgs.dev.azure.com/<organization>/_packaging/<feedname>/nuget/v3/index.json
[CredentialProvider]ATTENTION: User interaction required.
**********************************************************************
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXXXXX to authenticate.
**********************************************************************
[CredentialProvider]Device flow authentication failed. User was presented with device flow, but didn't react within 90 seconds.
[CredentialProvider]Using the ADAL UI flow for uri https://pkgs.dev.azure.com/<organization>/_packaging/<feedname>/nuget/v3/index.json. User sign-in required in a pop-up authentication window.
Needless to say; user interaction during headless build is not very efficient.
I found an article describing Azure Artifacts Credential Provider and thought this might solve the problem.
According to section Other automated build scenarios it should be sufficient to declare an environment variable VSS_NUGET_EXTERNAL_FEED_ENDPOINTS with content like:
{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/<organization>/_packaging/<feedname>/nuget/v3/index.json", "username":"optional", "password":"accesstoken"}]}
I replaced the "accesstoken" above with my own accesstoken, but still NuGet Push seems to depend on my %AppData%\Nuget\Nuget.Config.
The preferred solution would be to hold the Personal Access Token in a Jenkins Secret, and use that for Git clone and Git tag as well as for NuGet Restore and NuGet Push.
I find local config files and OS environment varables to be more problem prone, and would rather avoid them.

Cannot clone Git repository into sourcetree, Login screen keeps appearing

In BitBucket, when I select clone into source tree, the URL is of format
Sourcetree opens with details to clone, but keeps asking for my login details no matter how many times I enter them.
https://myname#bitbucket.org/mygroup/myrepository.git
I have no problems on a different computer ( also Windows 10 )
I have tried upgrading SourceTree and Reinstalling Source Tree
I have tried System Git and Embedded Git and reinstalling both Git
I can clone Mercurial repositories
At the Dos prompt I can type
git clone https://myname#bitbucket.org/mygroup/myrepository.git
I get a message
fatal: HttpRequestException encountered
An error occurred wihe sending the request
then it asks for my password
then it proceeds with the clone
However in sourcetree the repository shows that there are more branches to pull.
I am unable to pull these branches
When I go to the Tools->Options->Authentication tab I can see myname#bitbucket.org as an Account.
If I try to add myname#mydomain.com.au I get
Authentication failed
Invalid URL: The hostname could not be parsed.
Atlassian community
"The only thing that worked for me was navigating to C:\Users\USERNAME\AppData\Local\Atlassian\SourceTree and removing the passwd file."
Had the same problem , but on MacOS. Just for completion of the answer I will add that on MacOS the passwords are stored in the KeyChain Access and they need to be deleted from there.

Gerrit client -remote configuration

I have installed Git and Gerrit and prepared remote site.
I am facing communication issue between Client and Remote.
My Config file looks as below,
enter image description here
Error while doing clone,
Fatal: Could not read from remote repository
Please make sure you have the correct access rights.

How to access a public bitbucket repo via jitpack.io?

I'd like to use the latest version code from the public bitbucket project rxlint in my gradle project. But I don't know which URL to use.
I've tried to enter some URLs (see below) on https://jitpack.io/ - without success. The error message is always:
Repo not found or no access token provided
and since this repo is public, I guess, that I am just using the wrong format for the URL
URL's I've tried without success:
org.bitbucket.littlerobots/rxlint
https://bitbucket.org/littlerobots/rxlint
https://bitbucket.org/littlerobots/rxlint/src
git+ssh://git#bitbucket.org/littlerobots/rxlint.git
V1.2 tag: https://bitbucket.org/littlerobots/rxlint/src/a5e5d85b8358f74b33f5844ff154c80bc10d0009/?at=v1.2
tip tag: https://bitbucket.org/littlerobots/rxlint/src/462cbb708d8897480fc327e736acde50377b4e2c/?at=tip
You need to create authToken for this repository:
https://jitpack.io/docs/PRIVATE/#bitbucket
In order to Look Up and manage Bitbucket repositories you should add the App Password to your JitPack account:
Sign In on https://jitpack.io
Click on your username (https://jitpack.io/w/user)
Enter your Bibucket user and App Password
That project is hosted as a Mercurial (hg) repository on Bitbucket. JitPack only supports Git repositories.

connect to TFS with TortoiseGit or msysgit?

I made a new blank TFS git project and tried to clone it in a new folder on my desktop using TortoiseGit and msysgit. It always fails saying 'Authentication failed'.
I typed:
"git clone https://saratoga.visualstudio.com/DefaultCollection/_git/Git%20Test."
When prompted for my username I entered my Windows account email address (e.g. bob#example.org).
It then asked for my password for
"https://test#saratoga.visualstudio.com"
i entered the password. However, I am unable to connect to the tfs service, message appear that authentication failed in tortoise git.
Alternative Authentication Credentials in TFS provides a solution, use the following instructions:
Click on your name in the upper right of screen.
Click on My Profile.
Click on the Credentials tab.
Setup an alternate username that doesn't include the # character.
Now when you connect to the remote repo via TortoiseGit, you can use the alternate credentials and those new credentials should work.

Resources