Git最佳实践
Vincent Driessen 写的这篇A successful Git branching model很好的阐述了Git的最佳实践。
使用中央仓库作为整体的系统,使用主干——分支系统,具有真实的中央存储库。将中央存储库命名为origin。
所有的开发人员拉去和推送都到origin,开发人员不止可以从中央库pull和push代码,同样可以从其他开发人员的分支上push和pull代码。
主分支
Coding.net使用和从Github转移项目到Coding.net
coding.net可以使用私人仓库,用起来还蛮顺手的,因为新公司没有搭建GitLab服务器,但是又不想在github上付费开私人仓库。所以新公司项目就被我搭建在了coding.net里面。
搭建过程很简单,但还是写出来吧
一、搭建私人仓库,上传本地代码到仓库
去coding.net注册什么的不表,注册完成后点击创建项目
选择私有
下面那个启用README.md可以先不勾选,直接点击创建
创建完成
然后选择左侧代码~可以看到你的仓库地址
仓库地址
OK,下面在桌面上用Xcode新建一个项目,名称随意。创建完成后打开终端
cd到新建项目里面
touch README.md//新建一个记录提交操作的文档
git init //初始化仓库
git add README.md //添加README.md
git add * //检查所有项目
git status //检查状态 都为绿色证明是对的
git commit -m "first commit"//提交到本地仓库 first commit为提交说明
git remote add origin https://git.coding.net/cc412/Test.git //连接远程仓库 创建一个origin的别名
git push -u origin master //将本地仓库提交到origin下的master分支下
进行上面步骤
上传成功
返回到coding.net 进入Test项目
上传成功了
如果输出
fatal: remote origin already exists.
git remote rm origin
git remote add origin https://git.coding.net/cc412/Test.git
二、git转移
之前公司做的项目在我离职以后已经又推到重来了,旧的代码还托管在github上,现在我要把代码转移到coding.net上,还要保持所有commit记录
操作如下
1.首先找到github的托管地址
https://github.com/***/******.git
2.在coding.net上创建个新的私有仓库
过程同上,只是不用同步本地代码
比如新仓库地址为
https://git.coding.net/cc412/xxxx.git
3.在控制台cd到桌面路径
git clone --bare https://github.com/***/******.git
//--bare 创建的克隆版本库都不包含工作区,直接就是版本库的内容,这样的版本库称为裸版本库。
然后桌面就会出现一个xxxx.git 这就是在github上的项目
4.使用镜像推送的方式上传代码到新的服务器
cd xxxx.git
git push --mirror https://git.coding.net/cc412/xxxx.git
//https://git.coding.net/cc412/xxxx.git 是coding.net仓库地址
5.删除本地代码
cd ..//返回上一路径
rm -rf xxxx.git //干掉
6.从新服务器clone下来
git clone https://git.coding.net/cc412/xxxx.git
OK,大功告成
作者:cc412
链接:http://www.jianshu.com/p/93737d548a3d
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
git 记录
在使用内网github的时候发现问题
Empty reply from server
整理了一圈都发现,每次在git -T git@192.168.11.204
这样的时候都需要输入密码,但是不要用户名,实际上用户名又不对。
查了一圈看到git config里面有这样一行配置,应该是以前配置的用于走ss的
illiamtekiMacBook-Pro:sinhr valentine\( git config --list
credential.helper=osxkeychain
http.proxy=socks5://127.0.0.1:1080
core.excludesfile=_Users_valentine/.gitignore_global
difftool.sourcetree.cmd=opendiff "\)LOCAL" "\(REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=_Applications_SourceTree.app_Contents_Resources/opendiff-w.sh "\)LOCAL" "\(REMOTE" -ancestor "\)BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
设置代理使用
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
Copyright © 2020 鄂ICP备16010598号-1