首先下载一个git安装
在终端中用 git --version看git的版本号,如果有且符合你安装的版本,则说明安装成功。
然后创建一个全球用户名,这个用户名可以与git服务器上的用户名不一样
git config --global user.name "FIRST_NAME LAST_NAME"
再创建一个全球邮箱,这个邮箱需要和git服务器上的邮箱一致
git config --global user.email "MY_NAME@example.com"
进入你想要建立git本地库的文件夹,进行初始化
git init
将文件添加进本地库
git add filename
提交到本地仓库,就是给这次上传起一个名
git commit -m "message"
与服务器链接
git remote add origin ssh://username@10.10.10.108:29418/lianghua.git
上传到git服务器
git push -u origin master
有的可能需要先传一个README.md上去
touch README.md在本地建一个README.md
git add README.md添加到本地库
之后的操作参考上面
还有一些git的小技巧,
git status 看现在的状态
git push 提示 Everything up-to-date:那就使用需要commit一下,然后再上传
如果报下面这个错误
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@git.oschina.net:yangzhi/hello.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first merge 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 -f origin master
git remote -v 看自己的连接有没有问题
正常的是
origin https://code.google.com/p/micolog2 (fetch)
origin https://code.google.com/p/micolog2 (push)
这个结果
git branch 可以看自己现在的分支