git提交代码至GitHub

示例

git init xxx   //初始化仓库(工作区)

git add a.txt xy.sh    //上传两个文件至暂存区

git commit -m "first"    //上传至分支

git clone https://github.com/feiYufy123/tt       //克隆网址

git remote add origin https://github.com/feiYufy123/tt   //建立远程仓库

git push -u origin master     //提交

Username for 'https://github.com': feiYufy123     //GitHub用户名

Password for 'https://[email protected]':          //GitHub登陆密码

GitHub截图示例:

注释

ssh-keygen 命令中间没有空格,如果在ssh后面加上空格,会得到Bad escape character ‘ygen’.的错误

提示出错信息:fatal: remote origin already exists.

 解决办法:

 git remote rm origin

GitHub介绍

1. git

       管理代码的工具

2. 安装git

       sudo apt install git

       git –version

    git init (初始化仓库)

3. 配置git

       指定你的名字

              git config --global user.name 你的名字

       指定邮箱

              git config --global user.email 你的邮箱

4. git工作过程

       先从工作区add到暂存区,再从暂存区commit到分支

       默认有主分支master

5. 添加到暂存区的命令

       git add 文件名

6. 提交到分支的命令

       git commit -m 备注信息

7. 查看状态

       git status

GitHub

       远程代码托管的网站

1. 打开github的官网,注册一个账号

2. 右上角有一个头像的图标,这个图标里有一个setting的选项

       点开选项左边有一个SSH and GpG的按钮

       点击按钮打开页面里边有new ssh key的按钮。点击添加

3. 在linux终端中输入生成秘钥和公钥的命令

       ssh-keygen -t rsa -C 你的邮箱地址

       一路回车直到出现一堆文字

4. 在用户目录下有一个.ssh文件夹里有id_rsa.pub的文件

5. 通过cat命令查看文件的内容

6. 将文件的内容复制到github网页的key选项框里

7. 给title起个名字

8. 点击addsshkey添加按钮

在github上创建远程的项目(仓库):

1.点击右上角加号按钮第一个选项

2.给仓库起名字。

       点击readme选项(可选操作)

3.点击crete按钮创建即可

将github上的远程项目克隆到本地:

1.克隆命令(仓库或工作区)

       git clone 写github上创建的项目的地址

2.git remote add origin 写远程项目的地址(网址)

3.可以在本地仓仓库做一些添加上传的操作

4.上传到远程

       git push -u origin master

参考网站:

https://git-scm.com/book/en/v2 

猜你喜欢

转载自www.cnblogs.com/yu121/p/12950463.html