一、新建仓库

  1. 创建和进入一个空目录
    
    mkdir gitproj

cd gitproj


2. 初始化

git init


###二、clone 仓库

git clone httpxxxxxxxxxxxx


###三、加入代码

git add xxx.txt


增加所有改动的文件

git add -A


增加当前目录和子目录的文件

git add .


在windows上commit之前,要禁止CRLF转换,并解决中文文件名显示问题

git config --global core.quotepath false
git config --global core.autocrlf false

git commit -m 'xxxxx'


提交到远程仓库

git push

### 提交到新的远程仓库

git remote add origin https://e.coding.net/xxxx/postsales.git
git push

如果不想覆盖以前的仓库,可以这样增加一个新的push地址

git remote add kk https://e.coding.net/xxxx/postsales.git
git push kk


不错的站点:

http://www.ruanyifeng.com/blog/2014/06/git_remote.html

###四、每次git push不需要输入密码(windows)
第一个方法:
新建`C:\Users\你的电脑名\.git-credentials`文件
内容是:

https://username:password@github.com


第二个方法
执行如下命令:

git config --global credential.helper store

然后git push,这时会输入一次用户名密码,然后就会保存起来,保存在C:\Users\你的电脑名\.git-credentials,下次就不用输入了。
第三个方法(2018-12-15win7下检测失效)
在windows中添加一个HOME环境变量,变量名:HOME,变量值:%USERPROFILE%

进入%HOME%目录,新建一个名为"_netrc"的文件,文件中内容格式如下:

machine {git account name}.github.com
login your-usernmae
password your-password


重新git push即可,无需再输入用户名和密码

### TortoiseGit保存用户名和密码的方法
[TortoiseGit保存用户名和密码的方法](https://www.cnblogs.com/sapho/p/6140331.html)

标签: none 阅读量: 960

添加新评论