Git安装与Gitee基本使用

MAC上Git安装与Gitee基本使用

安装git

MAC 上安装Git主要有两种方式
首先查看电脑是否安装Git,终端输入:

git

安装过则会输出:

WMBdeMacBook-Pro:~ WENBO$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Reapply commits on top of another base tip
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

1、通过homebrew安装Git

  • 未安装homebrew,需安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 安装git
brew install git

2、通过Xcode安装

直接从AppStore安装Xcode,Xcode集成了Git,不过默认没有安装,你需要运行Xcode,选择菜单“Xcode”->“Preferences”,在弹出窗口中找到“Downloads”,选择“Command Line Tools”,点“Install”就可以完成安装了。

创建ssh key、配置git

  • 1、设置username和email(gitee每次commit都会记录他们)
git config --global user.name "XXX"
git config --global user.email "XXX@qq.com"
  • 2、通过终端命令创建ssh key
ssh-keygen -t rsa -C "XXX@qq.com"

XXX@qq.com是你的邮件名,回车会有以下输出

Last login: Sat Jan  6 14:12:16 on ttys000
WMBdeMacBook-Pro:~ WENBO$ ssh-keygen -t rsa -C "XXX@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/WENBO/.ssh/id_rsa): 
/Users/XXX/.ssh/id_rsa already exists.
Overwrite (y/n)? n
WMBdeMacBook-Pro:~ XXX$ 

由于这里我原来已经创建过,这里我选n,没有创建过的,会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
终端查看.ssh/id_rsa.pub文件

open .ssh/id_rsa.pub 

回车后,就会新弹出一个终端,然后复制里面的key。
或者用cat命令查看

cat .ssh/id_rsa.pub
3、登录https://gitee.com/(默认你已经注册了Gitee账号),添加ssh key,点击Settings,如图

在这里插入图片描述点击“SSH公钥”,如图
在这里插入图片描述
添加key,如图
在这里插入图片描述

4、链接验证

ssh -T git@gitee.com

终端输出结果
Last login: Sat Jan 6 14:42:55 on ttys000
WMBdeMacBook-Pro:~ XXX$ ssh -T git@gitee.com
Hi wenmobo! You’ve successfully authenticated, but Gitee does not provide shell access.
WMBdeMacBook-Pro:~ XXX$

说明已经链接成功。

5、下载项目到本地

首先复制ssh地址
在这里插入图片描述打开终端,这里只是测试,我想把工程克隆在指定目录,首先在终端中切换路径到指定目录,输入以下命令:

/e/workspace-python/test

然后克隆项目,终端输入

git clone git@gitee.com:xiaolaifeng/sample.python.git

git@gitee.com:xiaolaifeng/sample.python.gitt是刚刚复制的ssh路径。
终端完整输出如下:

indexvc@SHDN049 MINGW64 /e/workspace-python/test
$ git clone git@gitee.com:xiaolaifeng/sample.python.git
Cloning into 'sample.python'...
remote: Enumerating objects: 659, done.
remote: Counting objects: 100% (659/659), done.
remote: Compressing objects: 100% (598/598), done.
remote: Total 659 (delta 40), reused 656 (delta 40), pack-reused 0
Receiving objects: 100% (659/659), 4.32 MiB | 9.77 MiB/s, done.
Resolving deltas: 100% (40/40), done.

indexvc@SHDN049 MINGW64 /e/workspace-python/test
$ ^C

indexvc@SHDN049 MINGW64 /e/workspace-python/test

使用pycharm打开此项目即可

Window下Git安装使用

Git安装

下载Git,链接如下:https://git-scm.com/download/win

下载完毕,打开安装,按照安装流程一步一步执行,选择默认操作执行,直至该安装完成。

gitee托管项目代码

  • 配置Git

打开Git Bash应用,界面显示如下图所示。
在这里插入图片描述

  • 先输入ssh-keygen –t rsa –C “邮箱地址”,注意ssh-keygen之间是没有空格的,其他的之间是有空格的。

  • 回车之后,会出现一行,让你输入一个保存密钥的地方,括号里面是它默认的位置,这里会让你输入几次内容,都不用输入,直接回车就可以了,可以看到如图的效果。
    在这里插入图片描述

  • 回车之后,这样密钥就生成了,可以打开id_rsa.pub(上面一步可以看出创建的路径)来查看,里面的所有内容就是这个密钥,一会需要使用的时候,就直接全选复制就可以了。用记事本打开。

  • 登录https://gitee.com/(默认你已经注册了Gitee账号)

  • 验证一下是否设置成功,在git bash下输入如下命令,流程图如下图所示:

  • 现在配置一下用户名和邮箱:

 git config --global user.name “用户名”
git config --global user.email “邮箱”
ssh -T git@gitee.com

在这里插入图片描述

  • 在gitee创建仓库"sample.python",之后在gitbash中切换到自己本地代码文件目录,配置仓库
 mkdir sample.python
cd sample.python
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/xiaolaifeng/sample.python.git
git push -u origin master

执行结果如图
在这里插入图片描述

提交本地项目到Gitee

使用pycharm提交本地项目 (默认已经安装以上步骤配置好ssh)

  1. 打开pycharm,点击右上角push按钮
    在这里插入图片描述在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浮华落定

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值