I recently rebuilt my computer and cloned a git repository that I had been working on. Once I started working on the project again, I realised that every time I was executing a pull or push command in git bash it would ask me for my username and password whereas before it used to only request by password.
I checked my .gitconfig and it contained the correct details (under [user] i had name and email). I double checked that a second .gitconfig hadn’t been created elsewhere that was causing a conflict.
I eventually found out that it was because I had cloned the repository using the https url instead of the ssh. I just had to change the way I was connecting the remote repository, and that was done using the command below. Once I had done this my push and pull commands no longer asked for my username.
git remote set-url origin email@example.com:username/repo.git