Git本地init与push到远程仓库

1、先进行git配置项查看与修改初始化

.git删除:rm -rf .git

查看信息:git config --list

$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/APP/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
credential.helper=manager
...


修改信息,例如用户名与邮箱:

git config --global user.name "name"

git config --global user.email "email"

账号、密码修改

git config –system –unset credential.helper  #重置认证信息

git config –global http.emptyAuth true  #认证清除

(先进入项目文件夹)通过命令 gitinit 把这个目录变成git可以管理的仓库

git init

2、把文件添加到本地版本库中,使用命令git add 文件;添加到暂存区里面去,如果后面接小数点“.”,意为添加文件夹下的所有文件

git add .

3、用命令 git commit告诉Git,把文件提交到仓库。引号内为提交说明

git commit -m 'first commit'

4、关联到远程库

git remote add origin 你的远程库地址

如:

git remote add origin git@192.168.31.130:/srv/sample.git

如果上面步骤写错了:则      

git remote rm origin   #删除origin

git remote add origin git@git.oschina.net:yourname/demo.git   #重新添加origin

5、获取远程库与本地同步合并(如果远程库不为空必须做这一步,否则后面的提交会失败)

git pull --rebase origin master

6、将最新的修改推送到远程仓库

    备注:origin:远程仓库名字;master:分支

注意:我们第一次push的时候,加上-u参数,Git就会把本地的master分支和远程的master分支进行关联起来,我们以后的push操作就不再需要加上-u参数了

如果出现类似下面内容:

Username for 'https://github.com': shiren1118

Password for 'https://shiren1118@github.com':

To https://github.com/shiren1118/iOS_code_agile.git

 ![rejected]        master -> master(non-fast-forward)

error: failed to push some refs to'https://github.com/shiren1118/iOS_code_agile.git'

hint: Updates were rejected because the tip of yourcurrent 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.

则输入命令:git push -u origin master –f即可搞定问题

git push -u origin master

如果从在git服务器所在主机上的其他账户获取git服务器上面文件,则直接用

gitclone + git仓库的路径,即:

git clone /srv/sample.git/

7、复制分支并推送到远程仓库

# 从master切分出dev分支,并推送到远端
git checkout -b develop    

# 切换到功能开发分支
git checkout -b feature-[name_of_feature]  
 
# 进行功能开发,在阶段性完成之后,将代码合并回本地的dev分支
git checkout develop
 
# 确认分支代码为最新
git pull origin develop
 
# 注意,一定要添加--no-ff 标记
git merge --no-ff feature-[name_of_feature]
 
# 如果确认feature分支已经不需要了可以删除
# git branch -d feature-[name_of_feature]
 
# 代码提交到远端分支
git push origin develop

8、保存进度的列表

git stash  # git stash save 'message...'可以添加一些注释
git stash pop  #恢复最新的进度到工作区。git默认会把工作区和暂存区的改动都恢复到工作区,并且会删除当前进度。
git stash pop --index  #恢复最新的进度到工作区和暂存区。(尝试将原来暂存区的改动还恢复到暂存区)
git stash pop stash@{1} #恢复指定的进度到工作区。stash_id是通过git stash list命令得到的

  • 6
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值