【Git本地init与push到远程仓库】

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

.git删除:rm -rf .git

查看信息:git config --list


   
   
  1. $ git config --list
  2. core.symlinks= false
  3. core.autocrlf= true
  4. core.fscache= true
  5. color.diff=auto
  6. color.status=auto
  7. color.branch=auto
  8. color.interactive= true
  9. help.format=html
  10. http.sslcainfo=C:/APP/Git/mingw64/ssl/certs/ca-bundle.crt
  11. diff.astextplain.textconv=astextplain
  12. rebase.autosquash= true
  13. credential.helper=manager
  14. ...


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


   
   
  1. git config --global user.name "name"
  2. git config --global user.email "email"

账号、密码修改


   
   
  1. git config –system – unset credential.helper #重置认证信息
  2. 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

如果上面步骤写错了:则      


   
   
  1. git remote rm origin    #删除origin
  2. 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、复制分支并推送到远程仓库

   
   
  1. # 从master切分出dev分支,并推送到远端
  2. git checkout -b develop
  3. # 切换到功能开发分支
  4. git checkout -b feature-[name_of_feature]
  5. # 进行功能开发,在阶段性完成之后,将代码合并回本地的dev分支
  6. git checkout develop
  7. # 确认分支代码为最新
  8. git pull origin develop
  9. # 注意,一定要添加--no-ff 标记
  10. git merge --no-ff feature-[name_of_feature]
  11. # 如果确认feature分支已经不需要了可以删除
  12. # git branch -d feature-[name_of_feature]
  13. # 代码提交到远端分支
  14. git push origin develop
8、保存进度的列表

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值