Push and Pull to git with using SSH Keys

Ever experience that every time you pull or push to bitbucket it ask you to enter password if not both username and password?

Theres a better way to push and pull to git using ssh.

  • Generate public and private keys
$> ssh-keygen -t rsa 

If you already created ssh keys before then just copy the content of the public key

$> cat ~/.ssh/id_rsa.pub

If you are using bitbucket, go to settings

https://bitbucket.org/account/user/{yourusername}/ssh-keys/

and create ssh key the you copy

Add SSH Key
Add SSH Key

Take note to use the “SSH” version before cloning. or if you’re already using HTTPS, just edit git/config then replace the URL.

$> nano .git/config
[core]
 repositoryformatversion = 0
 filemode = true
 bare = false
 logallrefupdates = true
[remote "origin"]
 url = git@bitbucket.org:myteam/repo.git
 fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
 remote = origin
 merge = refs/heads/master

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.