Setting SSH Bitbucket/Git

Problem: Many developers, especial juniors, when using Git/Bitbucket, clone repository use HTTPS, but exist more better way – use SSH. Ok, but how it works? How we can configure it?

Configure SSH Git/Bitbucket

Solution: Follow the instructions step by step:

Step 1: Connect to SSH remote host:

ssh user_name@user_host

Step 2: Generate SSH keys, via run next command:


Step 3: Open file in hidden ssh folder:

vi .ssh/

Copy contain of the file to Bitbucket account - Settings - SSH Keys. Create new key and paste contain of file Save it. 

Step 4: Let's return on our server and make new folder as project name (domain name):

mkdir project_name_as_domain_name

Step 5: Change directory and moving from current folder to project folder:

cd project_name_as_domain_name

let's initialization Git into folder:

git init

configure Git

vi .git/config

add next setting into file:

	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = # replace this string on current project (use option SSH on Bitbucket/Git)
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

Step 6: Execute commands:

git fetch
git checkout -t origin/master

Step 7: Check files in current folder using ls -la. If files not found need execute:

git pull origin master

if we get project folder from Git repo in current folder e.g. project_name_folder/project_name_folder/files, and we need project_name_folder/files, need execute command for all content moving:

mv .[!.]* /home/u123456789/public_html/

If you get error

mv: cannot stat ‘.[!.]*’: No such file or directory

don't pay attention 🙂 Files was moved. Note: Use pwd comand that output current folder.

Leave Comment

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