1.应用场景

将本地代码与github仓库关联.

2.学习/操作

步骤  //这里以github为例

 

1.先在远程仓库(如github)创建项目, 建议为了避免错误, 先不要初始化 README, license, 或者gitignore文件.

 

2.打开git bash

 

3.切换到你的本地项目目录

 

4.初始化本地仓库  //如果已经加入git版本控制中, 跳过

git init

 

5、添加文件到本地仓库  

git add .


6.提交文件

git commit -m 'init code' //提交信息, 结合自身而定

 

7.到远程仓库的页面上,复制仓库地址 //这里以配置好ssh, 故复制ssh形式的仓库地址 也可以使用https方式,两者区别请另行查找资料


8.添加远程仓库地址到本地仓库

git remote add origin {远程仓库地址}

# Sets the new remote

git remote -v

# Verifies the new remote URL

 

9、push到远程仓库

git push -u origin master

 

 

总结:

就是要本地项目跟远程仓库建立联系, 方式可以有: 建立远程仓库后,本地git clone/git remote add origin {远程仓库地址}  

建立联系之后, 就可以进行版本控制, 可以把自己要修改的文件添加/修改/删除,在版本控制中管理, 与远程仓库推拉即可.

 

 

备注:

1.origin是本地为远程仓库起的名字, 可自行起名.

2.在github上创建新项目,如果没有成成README文件, 会有下步提示[很人性化]

文本如下: //四种情况, 都分别给出了提示操作.

Quick setup — if you’ve done this kind of thing before

 Set up in Desktop or HTTPS SSH git@github.com:ningxiaofa/laravel56.test.git

Get started by creating a new file or uploading an existing file. We recommend every repository include a READMELICENSE, and .gitignore.

 

…or create a new repository on the command line

echo "# laravel56.test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:ningxiaofa/laravel56.test.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin git@github.com:ningxiaofa/laravel56.test.git
git push -u origin master

…or import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

Import code  //点击跳转,输入仓库地址[https/ssh]即可

 

如下: //使用的是https地址

 

3.git push origin与git push -u origin master的区别

$ git push origin

上面命令表示,将当前分支推送到origin主机的对应分支.

如果当前分支只有一个追踪分支,那么主机名都可以省略,  使用

$ git push

 

如果当前分支与多个主机存在追踪关系,那么这个时候-u选项会指定一个默认主机,这样后面就可以不加任何参数使用git push

 

$ git push -u origin master

上面命令将本地的master分支推送到origin主机,同时指定origin为默认主机,后面就可以不加任何参数使用git push了.

 不带任何参数的git push,默认只推送当前分支,这叫做simple方式.

 

此外,还有一种matching方式,会推送所有有对应的远程分支的本地分支.

Git 2.0版本之前,默认采用matching方法,现在改为默认采用simple方式.

 

如下:

更多git操作见: 

https://blog.csdn.net/william_n/article/details/80288051

 

 

后续补充

...

3.问题

1. 如何转换仓库类型public或private类型? 

public->private: 

打开 https://github.com/ningxiaofa/blog57.test/settings

按照要求输入仓库名, 点击下方'I understand, ...'

重新输入密码确认, 即可

退出登录或者换个浏览器[没登录github相同账号]访问: https://github.com/ningxiaofa/blog57.test

结果如下: 表明正常生效  //实际上, 公司项目这样还是不推荐, 毕竟是托管在第三方仓库, 无法控制风险. 练手项目就暂时无所谓了.

Over

...

 

 

2. 删除仓库

从1中看到, 删除仓库等也在这里操作.  //请谨慎处理

 

 

 

4.参考

https://www.cnblogs.com/wangkongming/p/11527001.html

https://www.cnblogs.com/zhouj850/p/7260558.html

https://blog.csdn.net/william_n/article/details/80288051

后续补充

...

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐