mac使用git管理Github

工欲善其事,必先利其器。

在OS X Yosemite 10.10.3安装最新版本号Xcode。在terminal下能够发现git已经被安装。

~ mesut$ git --version
git version 2.3.2 (Apple Git-55)

之前就已经注冊而且使用Github了,只是一直都是在window 系统下远程管理。

如今開始设置Mac管理Github,有一点须要知道的是本地的git仓库和Githubserver之间是通过ssh加密的。

在终端运行

ozil:tmp mesut$ ssh -v
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-e escape_char] [-F configfile]
           [-I pkcs11] [-i identity_file]
           [-L [bind_address:]port:host:hostport]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-R [bind_address:]port:host:hostport] [-S ctl_path]
           [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]

明显Mac已经安装了ssh。


1:创建SSH Key

ozil:tmp mesut$ cd ~
ozil:~ mesut$ pwd
/Users/mesut
ozil:~ mesut$ cd .ssh
-bash: cd: .ssh: No such file or directory
ozil:~ mesut$ 

进入当前的用户文件夹。波浪线表示的是当前文件夹。

推断是否已经安装了.ssh,避免默认安装会覆盖之前安装的。

明显当前文件夹没有该文件

运行创建 ssh key

ssh-keygen -t rsa -C "youremail@example.com"(你的Github登陆名)

接着都是回车,选择默认的文件夹,默认的password就可以

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mesut/.ssh/id_rsa):     
Created directory '/Users/mesut/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/mesut/.ssh/id_rsa.
Your public key has been saved in /Users/mesut/.ssh/id_rsa.pub.


接着能够在用户主文件夹里找到.ssh文件夹,里面有id_rsaid_rsa.pub两个文件,这两个就是SSH Key的秘钥对

ozil:~ mesut$ cd .ssh
ozil:.ssh mesut$ ls
id_rsa		id_rsa.pub


2:在Github设置ssh key

登陆Github, “Settings”->"SSH keys"->"Add SSH key"






title:能够顺便填名字

key:在Key文本框里粘贴id_rsa.pub文件的内容

点击add key 配置完毕

3:測试本地是否和Github连接上

史蒂夫

ozil:.ssh mesut$ ssh -T git@github.com
The authenticity of host 'github.com (xxx)' can't be established.
RSA key fingerprint is xxx.
Are you sure you want to continue connecting (yes/no)? yes
第一次链接Github,会有一个确认。 须要你确认GitHub的Key的指纹信息是否真的来自GitHub的server,输入 yes 回车就可以。

Warning: Permanently added 'github.com,xxx' (RSA) to the list of known hosts.Hi tanchongshi! You've successfully authenticated, but GitHub does not provide shell access.

4:使用git在本地建立的项目更新到Github

ozil:githubspace mesut$ mkdir hellogithub
ozil:githubspace mesut$ cd hellogithub/
ozil:hellogithub mesut$ ls -ah
.	..
ozil:hellogithub mesut$ git init
Initialized empty Git repository in /Users/mesut/Documents/githubspace/hellogithub/.git/
ozil:hellogithub mesut$ ls -ah
.	..	.git
ozil:hellogithub mesut$ touch newfile
ozil:hellogithub mesut$ ls
newfile
ozil:hellogithub mesut$ git add newfile 
ozil:hellogithub mesut$ git commit -m 'first commit'
[master (root-commit) 2295d3e] first commit
 Committer: >v< <mesut@ozil.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 newfile

首先在本地初始化一个git仓库

因为之前没有配置username。所以首次commit会有提示。自己主动建立

设置方式

$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"


为了把本地库推到远程server,首先须要在Github上面也建一个项目


在Repository name填上我们的项目名字。description随便填,别的默认。

然后会生成项目

然后把远程项目和本地库关联

ozil:hellogithub mesut$ git remote add origin git@github.com:tanchongshi/hellogithub.git
ozil:hellogithub mesut$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'XXX' to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 217 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:tanchongshi/hellogithub.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.


https://github.com/tanchongshi/hellogithub

so far so good~


  • 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、付费专栏及课程。

余额充值