29 Jun Make Sublime Text 3 talk to Github
How to make Sublimetext 3 work with your online Github repository? Git is for version control, while GitHub is for sharing code. Here’s a five-step instruction how to connect Sublimetext to Git, and Git to GitHub.
This guide is for Windows, although the principles should apply to Mac, too.
Step 1: Install Git and GitSavvy if necessary
- Download and install Git from this Git download link for Windows (if necessary).. For Mac and Linux, check the Git Installation Page.
- In Sublimetext, install the GitSavvy package (if necessary). Hit
Ctrl + Shift + P
, then typePackage Contorol: Install Package
+ enter, then typeGitSavvy
+ enter. Also, fyi I’ll link to the package site of GitSavvy.
Step 2: Set up Git locally
Open the command line (in the Windows search bar, type cmd
, hit enter). Navigate into a folder that you want Git to version-control, using the cd
command. I’ll use “…\Projects\cognitivemodels”. Tell Git to flag this folder for version control , using git init
(line three shows the success message).
[code lang = “Shell Session”]> cd Users\Firstname\Projects\cognitivemodels
> git init
Initialized empty Git repository in C:/Users/Firstname/Projects/cognitivemodels/.git/[/code]
Step 3: Test if Git works with sublime locally
Information by GitSavvy about the changes to files we made. This works only if the file is within a folder that we have told Git about by running git init from within the folder in the command line.In Sublimetext 3 create a new “test.txt” file, save it to the folder (…\Projects\cognitivemodels). In Sublimetext type Ctrl + Shift + P
and git: status
+ enter. A new tab opens that looks as below. It shows you which files have changed, “UNSTAGED: test.txt” tells us that we added test.txt but we have not yet told Git’s version control system that there’s this file.
Place the cursor in the line “test.txt”, and hit the key s
, this lets Git know there is a changed file.
Hit the key c
, telling Git to save (commit) changes in all files that are staged (= files flagged as changed and to-be version-controlled).
A new file opens on Sublime. Enter a short commend e.g. “testing git” and hit Ctrl + Enter
. The file closes and you should see the above file again. You can close this.
Git now works locally from Sublime text.
Step 4: Making Git talk to GitHub
Open the program Git Bash (just search for it in the Windows search bar, it came with the Git installation). Type the line one below, replacing the email with your email address. Line two is the success message.
[code]ssh-keygen -t rsa -b 4096 -C “email_address@something.com”
Generating public/private rsa key pair.[/code]
When the console asks you to “Enter a file in which to save the key,” hit Enter
for the default folder.
When asked to “Enter a passphrase”, type in a new password
, hit enter, then repeat it. Make sure to not lose it.
[code lang = “Shell Script”]$ Enter passphrase (empty for no passphrase): …..
$ Enter same passphrase again: ….[/code]
Enter these two lines to tell Git about the key, enter your passphrase from above. (the last line is the success message):
[code lang = “Shell Script”]$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for …/.ssh/id_rsa:
Identity added: /c/Users/Yourname/.ssh/id_rsa (/c/Users/Yourname/.ssh/id_rsa)[/code]
In your folder “C:\Users\Yourname\.ssh” there is a file id_rsa_pub, open it with a text editor.
Go to GitHub (I assume you have a GitHub account), log in. In your GitHub account, go to Settings > SSH and GPG Keys > New SSH Key and paste the content of the id_rsa_pub file into there. Name and save. (More Info on this step on the GitHub help page, which this info is from.)
If you don’t use sublimetext: Make Git talk to GitHub
On GitHub create a new online repository with no README file, my GitHub repository is called cognitivemodels, like my local folder. Next, at the top-right of the page click on Clone or Download, and copy the url that appears, which should start with https
and look e.g. like https://github.com/FirstNameLastName/cogsciutils.git
. If the url does not start with https, click on Use HTTPS
. In your command line, add the GitHub remote like this, replacing “origin” with a name of your choice, replacing the url with your GitHub url:
[code lang = “Shell Script”]git remote add origin https://github.com/FirstNameLastName/cogsciutils.git[/code]
On your local machine, in the command line, navigate to a folder which you want to put online to GitHub (mine was: cognitivemodels). Make some changes. First stage and commit your changes to git on your machine.
In order to synchronize them to the online GitHub, what you want is the push
command, like this but replacing “origin” with your online repository name that you defined before/above:
[code lang = “Shell Script”]git push origin master[/code]
Step 5: Making Sublime talk to GitHub
Log in to Git Hub, open https://github.com/settings/tokens. Click Generate New Token, enter a description and select which parts of the GitHub stuff you want to be able to edit from Sublime, enter a description. I have one token described as “Admin” with all checkboxes checked. Click on “Crate new token” and copy the string-number-combination!! E.g. “09824mpö284027907139u23423098243”.
Open Sublimetext, and open Preferences > Package Settings > GitSavvy > Settings. Into the right window, enter this code, replacing 09824mpö284027907139u23423098243 by the string-number-combination that you have just copied from GitHub:
[code lang=”json”]{
“api_tokens”: {
“github.com”: “09824mpö284027907139u23423098243”
}
}[/code]
Try if Sublimetext talks to Github.
If you haven’t done so, go to the GitHub page, generate a new repository with no README file. I called my online repository like my local folder (cognitivemodels was my folder name), remember without a README or anything else. Click on Clone or Download on the right side and copy the text that appears, like “git@github.com:Myname/cognitivemodels.git”.
Go to Sublimetext, and hit Ctr + Shift + P
and git: remote add
and paste the text from before “git@github.com:Myname/cognitivemodels.git”, hit enter, and name it. I used “cognitivemodels” as name.
Again, type Ctr + Shift + P
and github: set remote for integration
, you will see a list with “origin” and “cognitivemodels”. Select cognitivemodels
.
In Sublimetext open your “test.txt” file, type Ctrl + Shift + P
and github: create pull request
.