Username and password in command for git push
Yes, you can do
git push https://username:[email protected]/file.git --all
in this case https://username:[email protected]/file.git
replace the origin
in git push origin --all
To see more options for git push
, try git help push
I used below format
git push https://username:[email protected]/file.git --all
and if your password or username contain @ replace it with %40
For anyone having issues with passwords with special chars just omit the password and it will prompt you for it:
git push https://[email protected]/YOUR_GIT_USERNAME/yourGitFileName.git
According to the Git documentation, the last argument of the git push
command can be the repository that you want to push to:
git push [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
[--repo=<repository>] [-f | --force] [--prune] [-v | --verbose] [-u | --set-upstream]
[<repository> [<refspec>…]]
And the repository
parameter can be either a URL or a remote name.
So you can specify username and password the same way as you do in your example of clone
command.
Git will not store the password when you use URLs like that. Instead, it will just store the username, so it only needs to prompt you for the password the next time. As explained in the manual, to store the password, you should use an external credential helper. For Windows, you can use the Windows Credential Store for Git. This helper is also included by default in GitHub for Windows.
When using it, your password will automatically be remembered, so you only need to enter it once. So when you clone, you will be asked for your password, and then every further communication with the remote will not prompt you for your password again. Instead, the credential helper will provide Git with the authentication.
This of course only works for authentication via https; for ssh access ([email protected]/repository.git
) you use SSH keys and those you can remember using ssh-agent
(or PuTTY’s pageant if you’re using plink).