mac下git与github简单使用

5 篇文章 0 订阅
准备工作:
       下载安装git客户端 http://code.google.com/p/git-osx-installer/downloads/list?can=3
       注册github账号 https://github.com/ -->Pricing and Signup -->Create a free account
创建ssh:
       在local打开terminal:
       $cd ~/.ssh  检查是否已经存在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      |
        |           .     |
        |                 |
        |                 |
        |                 |
       +-----------------+
       如果要修改ssh生成目录,在蓝色位置处输入要生成的路径,选择默认的话,会生成在 ~/.ssh下
在github中添加ssh:
       登陆github,选择Account Settings-->SSH Public Keys 添加ssh
       Title:xxxxx@gmail.com
       Key:打开你生成的id_rsa.pub文件,将其中内容拷贝至此
测试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.
        在蓝色位置处输入 yes
设置本地git个人信息:
        $git config --global user.name "your real name"
        $git config --global user.email "xxxxx@gmail.com"

至此,git和github的设置就完成了,下面就是如何将本地代码push到github上,以及如何从github上pull代码了:
在github中创建Repository:
      https://github.com/ --> New Repository 输入Repository信息 projectName
在本地创建代码库:
      创建一个文件夹作为local repository
      $mkdir test
      创建一个文件
       $cd test
       $vi test.txt
       将文件添加至local repository
       $git add test.txt
       初始化local repository
       $git init
       commit文件
       $git commit -a
       定义远程服务器别名
       $git remote add alias git@github.com:xxxxx/projectName.git
       将本地数据push到github上
       $git push alias master
这样就可以将本地的代码push到github的repository中了

从github中pull代码:
      在github中搜到你想要pull的代码,如https://github.com/edgecase/ruby_koans
      选择fork,将此repository fock到你的repository下
      在本地创建local repository并初始化
      使用命令:
      $git pull git@github.com:xxxxx/ruby_koans.git
      将github上的代码pull到local repository中

参考:
http://apps.hi.baidu.com/share/detail/16068052
http://blog.csdn.net/banxi1988/article/details/6555293
http://apps.hi.baidu.com/share/detail/31697631

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Git是一个分布式版本控制系统,用于跟踪文件的变化并协调多人在同一个项目上的工作。\[1\]Github是一个基于Git的代码托管平台,可以用来存储、管理和分享代码。\[1\] 在使用GitGithub之前,首先需要安装GitGit可以在多个操作系统上安装,包括Windows、Mac和Linux。你可以从Git官方网站下载适合你操作系统的安装程序,并按照安装向导进行安装。\[2\] 配置Github需要进行以下步骤: 1. 创建一个Github账号,如果已经有账号可以直接登录。 2. 在Github上创建一个新的仓库,用于存储你的代码。 3. 在本地的Git仓库中,将远程仓库克隆到你的电脑上,这样你就可以在本地进行代码的修改和提交了。\[1\] Git的标准工作流程是工作区→暂存区→Git仓库,但有时候可以跳过暂存区,直接将工作区中的修改提交到Git仓库。这可以通过在提交时使用git commit命令加上-a选项来实现。这样Git会自动将所有已经跟踪过的文件暂存起来一并提交,从而跳过git add步骤。\[3\] 希望这些信息能帮助你更好地理解GitGithub的基本概念和使用方法。如果你想深入学习GitGithub,我建议你参考廖雪峰老师的官方网站中的文章,那里有更详细和深入的内容。\[2\] #### 引用[.reference_title] - *1* *2* [手把手教你如何使用gitgithub](https://blog.csdn.net/m0_66614389/article/details/126617370)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [GitGithub使用](https://blog.csdn.net/DS153/article/details/123555356)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值