-
Check for SSH keys. Have an existing key pair? You can skip to Step 4.
First, we need to check for existing ssh keys on your computer:
$ cd ~/.ssh
If it says “No such file or directory“ skip to step 3. Otherwise continue to
step 2.
-
Backup and remove existing SSH keys.
Since there is already an SSH directory you’ll want to back the old one up and remove it:
$ ls
$ mkdir key_backup
$ cp id_rsa* key_backup
$ rm id_rsa*
-
Generate a new SSH key.
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.
$ ssh-keygen -t rsa -C "your_email@youremail.com"
Now you need to enter a passphrase.
Why do passphrases matter?
Which should give you something like this:
-
Add your SSH key to GitHub.
On the GitHub site Click “Account Settings” > Click “SSH Keys” >
Click “Add SSH key”
Open the id_rsa.pub file with a text editor (Notepad, TextEdit, or gedit will do just fine). This is your public SSH key. You may need to turn on “view hidden files” to find it because the
.ssh directory is hidden. It’s important you copy your SSH key exactly as it is written without adding any newlines or whitespace. Now paste it into the “Key” field.
Can’t view hidden files? Other ways to copy:
Now paste it into the “Key” field.
Hit “Add Key.”
-
Test everything out.
To make sure everything is working you’ll now SSH to GitHub.
Don’t change the “git@github.com” part. That’s supposed to be there.
$ ssh -T git@github.com
Which should give you this:
Don’t worry, this is supposed to happen. Type “yes”.
Having problems?
Then: Set Up Your Info
Now that you have Git set up and your SSH keys entered into GitHub, it’s time to configure your personal info.
-
Set your username and email.
Git tracks who makes each commit by checking the user’s name and email. In addition, we use this info to associate your commits with your GitHub account. To set these, enter the code below, replacing the name and email with your own. The name should be your
actual name, not your GitHub username.
$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "your_email@youremail.com"
More about user info
-
Set your GitHub token.
Some tools connect to GitHub without SSH. To use these tools properly you need to find and configure your API Token.
On the GitHub site Click “Account Settings”
At the command line run the following code, using your GitHub username and token in place of the ones shown.
$ git config --global github.user username
$ git config --global github.token 0123456789yourf0123456789token
*Note* If you ever change your GitHub password, a new token will be created and will need to be updated.
Create A Repo
If you’ve found yourself on this page, we’re assuming you’re brand new to Git and GitHub. This guide will walk you through the basics and explain a little bit about how everything works along the way.
First: Create A Repo
Every time you make a commit with Git, it is stored in a repository (a.k.a. “repo”). To put your project up on GitHub, you’ll need to have a GitHub repository for it to live in.
More about repositories
-
Create a new repo
Click New Repository.
Fill out the information on this page. When you’re done, click “Create Repository.”
Congratulations! You have successfully created your first repo!
Next: Create a README for your repo.
While a README isn’t a required part of a GitHub repo, it is a good idea to have one. READMEs are a great place to describe your project or add some documentation such as how to install or use your project.
More about READMEs
-
Create the README file
In the prompt, type the following code:
$ mkdir ~/Hello-World
$ cd ~/Hello-World
$ git init
$ touch README
Open the new README file found in your Hello-World directory in a text editor and add the text “Hello World!” When you are finished, save and close the file.
-
Commit your README
Now that you have your README set up, it’s time to commit it. A commit is essentially a snapshot of all the files in your project at a particular point in time. In the prompt, type the following code:
More about commits
$ git add README
$ git commit -m 'first commit'
The code above executes actions locally, meaning you still haven’t done anything on GitHub yet. To connect your local repository to your GitHub account, you will need to set a remote for your repo and push your commits to it:
More about remotes
$ git remote add origin git@github.com:username/Hello-World.git
$ git push -u origin master
Now if you look at your repository on GitHub, you will see your README has been added to it.
分享到:
相关推荐
Git使用教程
Git使用教程
GIT使用教程[收集].pdf
git详细教程,可快速学习使用git工具
Git使用教程
推荐Git的教程,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
git使用教程-史上最全,最简洁的使用教程
详细介绍开发过程中git的使用方法,包括本地使用,服务器搭建,可用协议介绍等内容,
Git使用教程.pdf
pro_git_中文版本(Git使用教程),团队远程协作代码合并,新手必备git使用指南
git使用教程1
Git使用教程:包括基础命令以及Sourcetree的使用
ios 开发 git使用教程,强烈推荐下载、最全版本,不要错过
git使用教程,学会使用git以及github远程仓库操作
2024最新Git使用教程HM
1. 类型: 文字版pdf,代码和内容...2. 简介: 这是官方git教程,资源压缩包里自带中文版和英文版,如不用英文版可忽略 3. 内容: 这是初学者学习git的最好教程,主要讲解了git的原理,以及git命令的使用。非常地amazing!