1、新建仓库/初始化仓库
git init
2、关联远程仓库
git remote add origin git@github.com:yourName/yourRepo.git
3、删除关联的远程仓库
git remote remove origin
4、添加文件
git add xxx
5、提交文件
git commit -m "备注"
6、向远程仓库推送本地仓库的改动
git push origin master
7、强制向远程仓库推送本地仓库的改动
git push -u origin master -f
8、报错:
$ git push -u origin master
To git@github.com:******/***.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/***.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
1)使用强制push的方法:使用第7点。但这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
2)push前先将远程仓库修改pull下来
git pull origin master
git push -u origin master
但可能还是会报错:
From github.com:***/***
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories
3)若不想merge远程和本地修改,可以先创建新的分支,然后再push
git branch [name]
git push -u origin [name]
9、LF will be replaced by CRLF | fatal: CRLF would be replaced by LF
参考文章[git] warning: LF will be replaced by CRLF | fatal: CRLF would be replaced by LF
10、.gitignore文件中添加忽略文件夹
# 本句为注释,忽略VS项目的隐藏文件夹.vs
.vs/
11、在github上进行了commit,但是contributions没有变绿:提交本地git的邮箱和github上的邮箱不是一个:
//查看本地git的邮箱
git config user.email
//本地git全局配置邮箱
git config --global user.email "***@gmail.com"