git 入门

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

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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值