Git 全局设置:
git config --global user.name "test" git config --global user.email "test@126.com"
创建 git 仓库:
mkdir test
cd test
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://git.oschina.net/demo/test.git
git push -u origin master
已有项目?
cd existing_git_repo
git remote add origin https://git.oschina.net/demo/test.git
git push -u origin master
git remote add origin https://git.oschina.net/demo/test.git
git push -u origin master
1、推送代码报错:
git push -u origin master
To https://git.oschina.net/demo/test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.oschina.net/demo/test.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方案
git push -u origin master -f
Counting objects: 27, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (27/27), 52.19 KiB | 0 bytes/s, done.
Total 27 (delta 3), reused 0 (delta 0)
To https://git.oschina.net/demo/test.git
+ 3bc80ef...74ec425 master -> master (forced update)
Branch master set up to track remote branch master from origin.
#git提交
定位到项目所在目录
##提交data下面的内容,或单独添加某一个文件的索引例如cofnig.json git add config.json
git add data/*
· git add -A 提交所有变化
· git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
· git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件
## 添加注释
git commit -m "add new members"
##提交到远程git服务器
###首次使用
git remote add origin https://git.oschina.net/demo/test.git
git push -u origin master
###非首次使用
git push origin master