Push to GitHub with the Terminal
Push to GitHub with the Terminal
GitHub is an online version control repository for code. It facilitates sharing and improvement of code. GitHub uses the Git platform to update code from a terminal.However, setting up a server to push changes to GitHub can be quite a pain.
Below is a guide on one way to set up such a server.
1. Generate a deploy key
Deploy keys allow a server to push changes to a GitHub repository. Open a terminal window and type the following command.$ ssh-keygen -t rsa -C "deploy key for repo"
You will be given a prompt to change the file name. Change it to reflect the name of your repository. For this example, the name will be "repo".
Generating public/private rsa key pair. Enter file in which to save the key (/home/usr/.ssh/id_rsa): /home/usr/.ssh/repo_rsa # change the file name to match your repo Enter passphrase (empty for no passphrase): # hit enter for no passphrase Enter same passphrase again: # hit enter for no passphrase Your identification has been saved in /home/usr/.ssh/repo_rsa. Your public key has been saved in /home/usr/.ssh/repo_rsa.pub.
2. Copy the deploy key to GitHub
Go to the settings page on your GitHub repository.Click "Deploy Keys" to the left of the page. Then on the deploy keys page, click "Add deploy key".
Give your key a title like "myComputer repo" and copy and paste all text in the .pub file you generated in step 1. into Key.
$ less /home/usr/.ssh/repo_rsa.pub # copy and paste all contents under # Key on GitHub
Check the "Allow write access" box and click "Add key"
3. Update ~/.ssh/config
Open (or create if not found) the file ~/.ssh/config and add the following lines.Host repo github.com Hostname github.com IdentityFile /home/usr/.ssh/repo_rsa
The first line defines the short-name of your repository. In this example it is "repo".
4. Clone the repository
Clone (or download) the GitHub repository with this command.$ git clone git@repo:GIT_USER_NAME/REPOSITORY_NAME.git
"repo" is the short-name defined in step 3. "GIT_USER_NAME" is the GitHub user name used to create the repository. "REPOSITORY_NAME" is the name of the repository.
You may need to configure git so pushes to GitHub are from your user name.
$ git config --global user.name "GIT_USER_NAME"
$ git config --global user.email EMAIL_ADDRESS_FOR_GITHUB
Test pushing changes
Open or create a "README.md" file in your repository directory. Type some text and save the changes.Push to GitHub with these commands
$ git add README.md
$ git commit -m "updated readme"
$ git push origin master
The first command ("git add") instructs which files to push to the repository. Wildcards "*" can be used with this command.
"git commit" provides a message describing the push. Here we updated README.txt and provide a vague explanation of the push.
"git push origin master" pushes the files added with "git add" to the repository. "master" is the branch name for this example, it is the default name for repositories on GitHub.
Comments
Post a Comment