Saturday, April 27, 2013

How do I install git and link my Linux machine to my BitBucket/GitHub account?

To start things off, connect to your remote machine:
ssh -p your_port you@your_ip_address
Now, see if you already have git installed:
which git
If your machine has git installed you'll see its path printed to your screen. Else, you'll need to install it:
sudo aptitude install git
You'll be prompted regarding incoming file size. Enter "yes". Now run:
which git
You'll see the program's path printed to your screen:
/usr/bin/git
Now we need to check and see if you have an ssh key pair on your machine or if we need to create one. To start off, we need to examine your remote machine. Run the following command:
cat ~/.ssh/id_rsa.pub
If the above command prints "No such file or directory", then you'll need to generate an ssh key pair before continuing. If the previous command printed a bunch of funny looking letters and numbers, then you already have an ssh key pair on your local machine that we can make use of!

Okay, so if your machine doesn't already have an ssh key pair on file, we can easily create one. Enter the following command:
ssh-keygen -t rsa -C "your_email@your_domain.com"
You'll be prompted with the following:
Enter file in which to save the key (/Users/you/.ssh/id_rsa):
Just press enter and "~/.ssh/id_rsa" will be used (which is what we want).

Next, you'll be prompted with the following:
Enter passphrase (empty for no passphrase):
Press enter twice to generate a key pair without a passphrase.

Now, at this point, everybody should have an "~/.ssh/id_rsa.pub" file on their remote machine. Next, log in to your BitBucket or GitHub account.

For BitBucket follow these steps:

  • Step 3) Print your machine's id_rsa.pub file content on the command line so you can manually copy it into memory:
    cat ~/.ssh/id_rsa.pub
    After copying it, without getting a single extra character accidentally added, paste it into your BitBucket account as shown in the following screenshot:


For GitHub follow these steps:

  • Step 3) Print your machine's id_rsa.pub file content on the command line so you can manually copy it into memory:
    cat ~/.ssh/id_rsa.pub
    After copying it, without getting a single extra character accidentally added, paste it into your GitHub account as shown in the following screenshot:
Next, config git to use your BitBucket/GitHub email address:
git config --global user.name "Your Full Name Here"
git config --global user.email your_repo_email@your_domain.com
Now, clone your project!

For BitBucket:
git clone git@bitbucket.org:your_username/your_project.git your_domain.com
For GitHub:
git clone git@github.com:your_username/your_project.git your_domain.com
In either case, you'll be prompted about "The authenticity of host...", enter "yes".

Boom! You're done! Way to go!

Lastly, if you're coming from my post titled, "How do I set up Apache virtual hosts on a Debian based Linux machine and configure to support HTTPS?", you can get back to it here: http://oneqonea.blogspot.com/2013/04/how-do-i-set-up-apache-virtual-hosts-on.html

2 comments:

  1. Hi John,

    Really great posts on this site. I've followed a few- really good work. Just wondering on this one....could this be a good replacement to using sftp to get my files across to my server? Would I make changes, push to git hub and then push to my server via git somehow....not at all familiar with git hence the question.

    Thanks

    ReplyDelete
    Replies
    1. Heyyoo,

      Thanks. I'm glad you dig the site.

      Yes. Git is an awesome alternative to using sftp to get your files across to your server. You'll work day to day git pushing and pulling from your local machine to Bitbucket/Github. Once you've done the "push" to Bitbucket/Github that you'd like to see on your server, you can ssh into your server and run a git pull (note: you'll need to set up your server similarly to how you set up your local machine with Bitbucket/Github i.e. you'll need to register the identity of your server with Bitbucket/Github (server's id_rsa.pub) or use read-only deploy keys ).

      I think this answers your question. If not, let me know!

      Delete

About Me

My photo
I code. I figured I should start a blog that keeps track of the many questions and answers that are asked and answered along the way. The name of my blog is "One Q, One A". The name describes the format. When searching for an answer to a problem, I typically have to visit more than one site to get enough information to solve the issue at hand. I always end up on stackoverflow.com, quora.com, random blogs, etc before the answer is obtained. In my blog, each post will consist of one question and one answer. All the noise encountered along the way will be omitted.