mc02_配置本地git仓库并上传到github

注册github账号

仔细阅读使用说明便可,这里提一下如何删除一个repository。

点击要删除的repository,打开后点击Settings

然后滚动到页面最下方,点击最后一个按钮

在弹出框中再次输入repository的名称,确认后删除

 创建一个reposition

 创建后有以下提示,下面在安装git后按提示操作

…or create a new repository on the command line

 
echo "# dao" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/tanpf/dao.git git push -u origin master

下载git软件并安装

这里使用的是Git-2.14.1-64-bit,在windows上下一步下一步即可

git bash,它把windows上的操作转化为linux shell类似的操作,通过在里面执行一些命令来实现git的功能。

比如,进入G:\all\code\git目录并创建javafx目录

配置全局邮件与名称

cd /d/code/git

mkdir dao

cd dao 

git config --global user.email "[email protected]"

git config --global user.name "tanpf"

若添加后则可以替换

git config --global --replace-all user.email "[email protected]"

git config --global --replace-all user.name "tanpf"

邮箱与名称可以自定义。

进入创建的目录,准备以该目录为根目录同步github

cd /d/code/git/dao

创建一个文件,github建议目录下放的说明文件

echo "# dao" >> README.md

将该目录初始化为一个git仓库目录 

git init 

将README.md文件添加到仓库

git add README.md

写一句文字说明并提交本次添加的文件到本地仓库,m 就是message

git commit -m "first commit"

在远程github与本地仓库间建立联系

git remote add origin https://github.com/tanpf/dao.git

将新提交到本地仓库的文件推送到github的master分支,github默认第一个分支的名称为master

git push -u origin master

该步骤会提示连接github所需要的用户名与密码,输入即可。再次查看github上,文件已经传送完成。

配置SSH为传输的内容加密

执行以下命令并输入三次回车(邮箱名称可自定义)

ssh-keygen -t rsa -C "[email protected]"

在github上添加本地ssh公钥

SSH and GPG keys --> New SSH key

cat id_rsa.pub 将 id_rsa.pub的内容添加到key中

cd /d/code/git/dao

cp -r /d/wkspace/workspaces/javafx/ppcore/ .

git add .

git status

git commit -m "ppcore first commit"

git push origin master

这是第二次提交,push没有加-u

 文件删除

删除本地文件

cd /d/code/git/dao

rm -rf ppcore/

git commit -m "rm ppcore"

从本地git仓库删除

git rm -rf ppcore/

git commit -m "rm ppcore"

从github分支上删除该文件

git add .

git commit -m "rm ppcore"

git push origin master

猜你喜欢

转载自www.cnblogs.com/perfei/p/9347496.html