Git with Atom
Git with Atom
by Jeff on August 29th, 2016 No Comments »
 , ,

This acticle will cover using Git with Atom editor via the Git-Plus Atom plugin. I am using Github, so the directions here may vary if you are using a different git provider, such as bitbucket. Integrating Git with Atom will integrate Git commands with the Atom GUI.

  1. Get Git
  2. Setup Git Variables
  3. Setup SSH Key
  4. Add SSH Key to GitHub
  5. Validate your SSH Key
  6. Initialize Git Rep
  7. Using Git with Atom
  8. Troubleshooting


Download Git for Windows

Git for Windows will install some required items for using Git with Atom; such as Git and Git Command Line. I like using the GitHub for Windows application, as I can always resort to the GUI if needed.


Setup SSH Keys

SSH Keys will allow easy syncs in git with Atom without requiring username/password combinations. To make things easier, I will use a combination of PuTTYGen and Pageant. I found it challenging to configure Git-Plus to use the default OpenSSH that comes with Git.

Download PuTTYgenm, plink and Pageant

PuTTYgen, plink and Pageant are free, open source applications that have been around for a long time. These applications can be downloaded here.
PuTTYgen – Used to create new public/private keys. The public key will be added to GitHub and the private key will be used in Pageant
plink – Command line interface that uses pageant as the SSH repository. We will configure plink as our GIT_SSH application.
Pageant – Used as a centralized public/private key repository.

Create the SSH Key

Launch PuTTYgen, you may receive a “Windows SmartScreen” warning, click “More Info” and run anyway
smartscreen
With PuTTYgen open, click on the “Generate” button. You will be asked to move your mouse around the application, this will ensure the use of random numbers. Once the Key has been generated, copy the contents. This is your public key that will be uploaded to GitHub. Now, click “Save private key” and save this file in a known location and name it git-ssh.ppk. You can set a passphrase to encrypt the key here, I recommend that you do. Just know that you’ll have to enter the passphrase each time it is loaded with Pageant.

PLink will be configured as our GIT_SSH application, therefore, you should move plink.exe from your downloads folder to a less volatile location. I like to use C:\Admin\Apps to store my standalone applications.

Now that the keys are generated, we need to add the private key to Pageant. If you have just downloaded Pageant, it may be wise to move the downloaded executable to a location outside of your downloads directory. You don’t want to accidentally delete the application while purging your downloads. Launch Pageant by double clicking on pageant.exe. This will start a small background application with an icon in your task bar where you can add private keys. Right click on the icon pageanticon and click “Add Key”. Browse to the private key you saved from the previous step (git-ssh.ppk) and load it. If you set a passphrase while generating the key, you will need to enter it now. If the key was added without error, you can move on to the next step.


Set GIT_SSH Environment Variable

In order for Git with Atom to use our newly generated SSH keys, we will need to add an environment variable called GIT_SSH. This variable tells GIT-Plus which application to use for SSH connections, in this case, plink. In the previous step I recommended moving the plink.exe from Downloads to a more persistent location. In my case, I moved it to C:\Admin\Apps\plink.exe. Take note of the plink.exe location now and move on to the next section.


Setup Git Variables

  1. Open Control Panel
  2. Naviage to Control Panel->System and Security->System
  3. Click “Advanced System Settings”
  4. Click “Environment variables”
  5. Select “PATH” and click “Edit”
  6. Add a new Path variable that points to your Git cli location
    • This is typically installed under C:\users\you\AppData\Local\GitHub\PortableGit{hash}\cmd
  7. Add a new “User variable” by clicking on the “New…” button under “User variables for {username}”
  8. Enter GIT_SSH as the “Variable name:”
  9. Enter the location of plink.exe as the “Variable value:”. In my case, C:\Admin\Apps\plink.exe
  10. git_ssh_var

Launch Git Shell and issue the following commands

git config user.name {git username}
git config user.email {git email address}


Add SSH Key to Github

In order to allow Git with Atom to use SSH to sync repositories, you must add the SSH public key to Github. You should have copied the RSA public key in the previous step. Now, log into Github.com and navigate to your repository. Click on “Settings”, click on “Deploy keys” then click “Add deploy Key”, give the key a name and paste the contents of the public key and check “Allow write access”.


Validate your SSH Key

This step is very important as it validates your public/private SSH keys and installs Githubs server key. Without this, you will see errors when trying to use Git with Atom.
In the Git Shell, issue the following command
Type the command exactly as it appears below, do not replace the URL with your own

ssh git@github.com

If asked to trust/install a certificate, accept it.
You should see a message similar to

Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi {username}! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.


Initialize our Git repo

Now we must add a Git repository to add to Atom. Since we are using SSH to integrate Git with Atom, we will need the SSH link to our Git repo.

  1. Log into github.com
  2. Navigate to your repository
  3. Click the “Clone or Download” button
  4. Click “Use SSH” in the top right
  5. Copy the contents of the text box

ssh-clone-github

From the Git Shell, issue the following command
Replace {link} with the link you copied in the previous step
Make sure you are in the directory you wish to place to your local git repos

git clone {link}

CD into your repo directory.

cd {repo}

Initialize the Repo

git init

Swith branches
If you do not with to use the master branch, or whichever branch is default, you can change branches by issuing the following command

git checkout --track origin/{branch}

Open Git with Atom

Now that you have your Git repo synchronized, you can open Git with Atom.

  1. Launch Atom
  2. Click “File”->”Add Project Folder”
  3. Browse to the Git directory created in the steps above


Using Git with Atom

Now that your repo has been added to Atom, you can start using git with Atom. To use Git-Plus, press the Git-Plus key combiniation
Windows

CTRL+SHIFT+H

Mac OSX

CMD+SHIFT+H

Let’s add a file and check it in to ensure Git with Atom is working properly.

  1. Create a new test file call testfile.txt
  2. Add the some test text “hello world”
  3. Save the file
  4. Add and Commit and Push
    • Press CTRL+SHIFT+H or CMD+SHIFT+H
    • Type “push”
    • Click on “Add And Commit And Push”
    • add-and-commit-and-push
    • Add a comment in the COMMIT window and Save the comment. Saving will trigger the sync
      • test-commit

Validate that the new file is listed in Github.


Troubleshooting

Error: Git is not a recognized internal or external command
git-is-not-recognized
Make sure you added Git to your PATH environment variables. See the top of this article

If you have added the Git to your PATH variable, try closing and re-opening Atom.

You should now be able to use Git with Atom and synchronize your branches.