mac下用git操作(push、pull)过程及注意事项

本文详细介绍如何在本地安装Git,配置SSH密钥,并将其与GitHub账户关联。此外还讲解了如何设置本地Git个人信息、推送本地代码至GitHub以及从GitHub拉取代码的过程。

1、安装git:http://git-scm.com/download/
2、检查是否已经存在ssh (命令:$cd ~/.ssh)

   如果存在,先将已有的ssh备份,或者将新建的ssh生成到另外的目录下
   如果不存在,通过默认的参数直接生成ssh
   生成过程如下:
   $ssh-keygen -t rsa -C xxxxx@gmail.com(注册github时的email)(注意空格)
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/twer/.ssh/id_rsa): 
    Created directory '/Users/twer/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /Users/twer/.ssh/id_rsa.
    Your public key has been saved in /Users/twer/.ssh/id_rsa.pub.
    The key fingerprint is:
    18:16:11:c9:01:6c:48:09:7f:27:c6:43:0d:7f:3f:84 xxxxx@gmail.com
    The key's randomart image is:
    +--[ RSA 2048]----+
    |.o.++===         |
    |.ooo.+. .       |
    |  ..* = E .      |
    |   o = + o       |
    |      . S o      |
    |           .     |
    |                 |
    |                 |
    |                 |
   +-----------------+

3、 在github中添加ssh:

   登陆github,选择Settings-->SSH Keys 添加ssh
   Title:xxxxx@gmail.com
   Key:打开你生成的id_rsa.pub文件,将其中内容拷贝至此(路径在第2步)

4、测试SSH:

   $ssh git@github.com
   The authenticity of host 'github.com (207.97.227.239)' can't be established.
   RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
   Are you sure you want to continue connecting (yes/no)? **yes**
   Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
   PTY allocation request failed on channel 0
   Hi xianfuying! You've successfully authenticated, but GitHub does not provide shell access.
            Connection to github.com closed.
   设置本地git个人信息:
   $git config --global user.name "github用户名"
   $git config --global user.email "注册邮箱"

5、将本地代码push到github

   先在github中创建Repository:
   https://github.com/ --> New Repository 输入Repository信息 projectName
   在本地创建代码库:              
   $mkdir test   //创建一个文件夹作为local repositor
   $cd test     
   $vi test.txt  //创建一个文件(代码?)
   $git add test.txt //将文件添加至local repository
   $git init    //初始化local repository
   $git commit -m "first" //commit文件 不能为空否则会出错(“commit -a” 又没有添加说明会出错)
   git remote add origin https://github.com/用户名/projectName.git 
   //定义远程服务器别名(origin可随便取)但不能重复 若为重复错误 可rm别名重新定义:git remote rm origin
   $git push -u origin master//将本地数据push到github上

6、从github中pull代码:

  使用命令:
  $git pull https://github.com/用户名/项目名  //将github上的代码pull到local repository中
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值