美文网首页
github上传代码

github上传代码

作者: Cursor_fei | 来源:发表于2016-08-15 15:18 被阅读27次

0.开头

在github上注册账号并简历仓库后,上传本地数据前需要配置SSH,SSH用于进行身份认证(git是分布式的代码管理工具,远程代码管理是基于ssh的,所以使用远程的git需要ssh的配置)。

关于windows:
如果你使用的是windows系统,建议使用 GitHub for Windows ,安装这个软件也会附带Git Bash工具,并且比通过 git 命令进行版本管理方便的多。

1.git配置

windows用户需要下载安装Git Bash,linux通过终端安装git。安装完后对git进行配置(配置过的用户可以通过git --lis命令查看配置):

$ git config --global user.name "xxx"
$ git config --global user.email "xxx@abc.com"

2.SSH生成

在Git Bash或者终端中,输入以下代码,用你的github邮箱替换其中的邮箱地址:

ssh-keygen -t rsa -b 4096 -C "*your_email@example.com*"
# Creates a new ssh key, using the provided email as a label
Generating public/private rsa key pair.

当界面提示:"Enter a file in which to save the key,"时,直接回车使用默认存储地址(默认地址为:~/.ssh):

Enter a file in which to save the key (/Users/*you*/.ssh/id_rsa): *[Press enter]*

然后提示输入密码和确认密码,此处可以按回车跳过。

Enter passphrase (empty for no passphrase): *[Type a passphrase]*
Enter same passphrase again: *[Type passphrase again]*

然后可以看见提示,ssh生成到此完成。

Your identification has been saved in /home/<user>/.ssh/id_rsa.
Your public key has been saved in /home/<user>/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:********** <youemail>@123.com
The key's randomart image is:
******

ssh生成完成后会在~/.ssh文件夹看到两个文件(默认存储路径时):

默认ssh路径下

3.添加SSH key到ssh-agent

确定ssh-agent是否可用:

  • 如果你使用Git Bash或者终端,键入如下命令打开ssh-agent:
  # start the ssh-agent in the background
  $ eval "$(ssh-agent -s)"
  Agent pid 59566
  • 如果你使用其他的终端,例如Git for Windows,请键入如下命令打开ssh-agent:
# start the ssh-agent in the background
$ eval $(ssh-agent -s)
Agent pid 59566

将SSH key添加到ssh-agent:

$ ssh-add ~/.ssh/id_rsa

4.在你的gitbug账户中添加一个新的SSH key

拷贝SSH key:

  • 通过xclip拷贝,在终端中执行以下命令:
$ sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
  • 直接拷贝。通过编辑器打开id_rsa.pub,或者通过cat等命令直接查看id_rsa.pub文件,并且选中内容拷贝。

在你的github主页选择Settings->SSH and GPG keys->New SSH key or Add SSH key
在title中输入这个ssh key的名称,用于自己辨识。在key中粘贴刚刚复制的数据。
然后点击Add SSH key,进行github密码验证后即可添加成功。

5.git常用操作

  • git init //初始化,在此文件夹中建立空的git库
  • git clone url //同步远程的库
  • git add . //添加所有修改过的文件(仅添加,未上传,或者说未保存到本地库)
  • git commit -m "说明" //真正的上传文件(保存到本地库)
  • git remote add origin url //远程上传到指定地址
  • git push -u origin master //上传到远程库

相关文章

  • Leetcode 88. Merge Sorted Array

    Python 3 实现: 源代码已上传 Github,持续更新。 源代码已上传至 Github,持续更新中。

  • Leetcode 21. Merge Two Sorted Li

    Python 3 实现: 源代码已上传 Github,持续更新。 源代码已上传至 Github,持续更新中。

  • Leetcode 9. Palindrome Number

    Python 3 实现: 源代码已上传 Github,持续更新。 源代码已上传至 Github,持续更新中。

  • Leetcode 4. Median of Two Sorted

    Python 3 实现: 源代码已上传 Github,持续更新。 源代码已上传至 Github,持续更新中。

  • 上传github 代码

    一、注册github账号 首先需要注册一个github账号,注册地址:https://github.com 接着会...

  • 代码上传github

    1.先在github上新建一个远程仓库,仓库名字一般写框架名字 2.将远程仓库上的代码(里面只有一些初始化的东西)...

  • 代码上传github

    1.首先注册github账号,登录,创建新仓库,点击+,点击new repository 2.填写仓库名,自己随便...

  • Github代码上传

    # Github代码上传 # ## 打开Github,注册账号,创建新的项目 ## https://github....

  • Leetcode 64: Minimum Path Sum

    动态规划 Python 3 实现: 源代码已上传 Github,持续更新。 源代码已上传至 Github,持续更新中。

  • Leetcode 7. Reverse Integer

    整型反转,Python 3 实现: 源代码已上传 Github,持续更新。 源代码已上传至 Github,持续更新中。

网友评论

      本文标题:github上传代码

      本文链接:https://www.haomeiwen.com/subject/whsusttx.html