博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Github 基本操作
阅读量:7006 次
发布时间:2019-06-28

本文共 2578 字,大约阅读时间需要 8 分钟。

.配置Git

首先在本地创建ssh key;

$ ssh-keygen -t rsa -C "your_email@youremail.com"

后面的your_email@youremail.com改为你的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。

回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。为了验证是否成功,在git bash下输入:

$ ssh -T git@github.com

如果是第一次的会提示是否continue,输入yes就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。

接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们。

$ git config --global user.name "your name"

$ git config --global user.email "your_email@youremail.com"

 

-------------

接下来在本地新建一个文件。放在你想要放的目录下面

$ mkdir TestProject 

 

进入到刚创建的目录下面

cd TestProject/

 

新浪一个测试文件。等会把这个测试文件传到github 上面去

$ vi test.txt 

 

初始化这个文件

$ git init

 

查看状态

$ git status

# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# test.txt

 

输入如下命令

$ git add test.txt 

 

再次查看状态的时候发现跟上面的有所不同

$ git status

# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: test.txt

 

提交

$ git commit -m "add a new file"

[master (root-commit) 45e61bc] add a new file
1 file changed, 4 insertions(+)
create mode 100644 test.txt

 

OK本地仓库已建好。接下来登录github 在上面新建一个仓库,建好后就把刚才本地的文件push 上去。

选择右上角的create a new repo 

建好后上面会有提示命令

Create a new repository on the command line

touch README.mdgit initgit add README.mdgit commit -m "first commit"git remote add origin git@github.com:qingjoin/TestProject.gitgit push -u origin master

Push an existing repository from the command line

git remote add origin git@github.com:qingjoin/TestProject.gitgit push -u origin master 回到本地Terminal

输入命令

$ git remote add origin git@github.com:qingjoin/TestProject.git

 

再查看一下

$ git remote -v

origin git@github.com:qingjoin/TestProject.git (fetch)
origin git@github.com:qingjoin/TestProject.git (push)

 

最后push

$ git push origin master

Counting objects: 3, done.
Writing objects: 100% (3/3), 246 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:qingjoin/TestProject.git
* [new branch] master -> master

 

然后回到github看下。刚才就已经上传了一个文件。

 

 

通过git diff命令,用户可以查看更改。通过改变一个文件的内容,看看gitdiff命令输出什么,然后提交这个更改到仓库中

# Make some changes to the fileecho "This is a change" > test01echo "and this is another change" > test02# Check the changes via the diff command git diff# Commit the changes, -a will commit changes for modified files# but will not add automatically new filesgit commit -a -m "These are new changes"
查看更新内容 git diff 提交更新  git commit -a -m "These are new changes" 上传 git push origin master

 

 

 

 

转载地址:http://vujtl.baihongyu.com/

你可能感兴趣的文章
MySQL逻辑架构简介
查看>>
网上找的Gif图片解析类
查看>>
node.js初学遇到的问题
查看>>
hibernate08--OpenSessionInView
查看>>
转载 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法...
查看>>
配置ORACLE 客户端连接到数据库
查看>>
drop asm disk、撤销drop asm disk
查看>>
Standby Redo Log 的设定原则、创建、删除、查看、归档位置
查看>>
[十二省联考2019]异或粽子
查看>>
winform 皮肤
查看>>
判断给定字符串中的大括号是否闭合
查看>>
MVC5+EF6 简易版CMS(非接口) 第二章:建数据模型
查看>>
Python 练习
查看>>
Silverlight知识点
查看>>
步步为营:Asp.Net序列化与反序列化
查看>>
论php数组合并
查看>>
内网域名配置方法
查看>>
我的Visual Studio必用工具
查看>>
Java语法
查看>>
【转载】白话经典算法系列之四 直接选择排序及交换二个数据的正确实现
查看>>