mac git 的一些总结

本文介绍了如何安装配置Git,设置全局用户名与邮箱,初始化本地仓库并上传文件至服务器的步骤。此外,还提供了解决常见错误的方法及一些提高工作效率的小技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先下载一个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 可以看自己现在的分支

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值