I have a set of private Git repos in BitBucket. I want to clone them through SSH so that the cloning can be automated without asking for a password. However, I want to push over HTTPS because I want to push with a different user name.
The PC is a common PC, and I want to distinguish who pushes changes but I do not care about who clone them.
Is there any way to do this? Thanks!
While SSH is usually considered more secure, for basic usage of Github, HTTPS authentication with a password is acceptable enough. In fact, Github themselves defaults to and recommends most people use HTTPS.
Git used SSH protocol to securely transfer repository data over the internet. Uses public key encryption to secure data. Git with HTTPS uses public-key encryption-based authentication for doing every action like git push, git clone, git fetch and git pull, etc.
You can use two or more different remotes for that. By default, when you clone a remote repository, the remote origin
is automatically created for you. But you can specify a different repository on the git command line each time literally like e.g.
git push https://git-server/myrepo.git branch
but it is much more convenient to add them as named remotes if you plan to use them more than once. Here is a more complete example transcript:
git clone ssh://user1@git-server/myrepo.git
cd myrepo
git remote add push https://git-server/myrepo.git
Then you can git fetch origin
or git pull
to update the local checkout, and you can push with e.g. git push push branch
(Note that the second push
here is the name of the remote). This way, you can also specify a different ssh remote with a different user:
git remote add push2 ssh://user2@git-server/myrepo.git
Then you can do git push push2 branch
in order to push via ssh as a different user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With