Mac 版 IDEA 中配置 GitLab
创始人
2024-12-28 02:34:07
0

一、安装Git

mac终端输入Git检测指令,可以通过git命令查看Git是否安装过,如果没有则会弹出安装按钮,如果安装过则会输出如下信息。

WMBdeMacBook-Pro:~ WENBO$ git usage: git [--version] [--help] [-C ] [-c name=value]            [--exec-path[=]] [--html-path] [--man-path] [--info-path]            [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]            [--git-dir=] [--work-tree=] [--namespace=]             []  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 ' or 'git help ' to read about a specific subcommand or concept. 

安装Git的方式有三种:
【方式一】通过homebrew安装GitHomebrewmacOS的一个包管理工具,如果未安装homebrew,需先安装homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

再通过如下命令安装git

brew install git 

【方式二】Git官网下载最新git Mac版本安装:下载地址Binary installer二进制安装,点击下载的git-2.27.0-intel-universal-mavericks.dmg安装。

【方式三】安装XcodeXcode安装完太大,占用空间,如果不需要安装Xcode,最好选择方式二安装git。打开终端输入git会弹出安装Xcode和安装git或者打开App Store搜索Xcode安装。XcodeApple官方IDE,功能非常强大,是开发MacIOS App的必选装备,而且是免费的。它集成了Git和一些插件,但是安装起来很大

二、配置Git 【创建ssh key】

【1】设置usernameemail 通过终端输入以下命令来配置用户名和邮箱,这些信息将用于记录你所有的提交历史:也可以通过git config --list查看已经设置的配置信息。

git config --global user.name "username" git config --global user.email "email" 

【2】创建SSH Key 在使用Git进行远程仓库的推送Push或拉取Pull时,为了验证你的身份通常需要使用SSH密钥。在终端中输入ssh-keygen,然后按下回车,接着连续按三次回车即可在你的用户目录(一般是/Users/your_name)下生成.ssh文件夹,并包含你的SSH Key

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

方式一: 在终端查看.ssh/id_rsa.pub文件:

open .ssh/id_rsa.pub  

回车后,就会新弹出一个终端,然后复制里面的key

方式二:cat命令查看

cat .ssh/id_rsa.pub 

【3】将SSH Key添加到你的GitHub 或者GitLab账号或其他远程仓库的账户设置中,就可以开始你的代码托管之旅。
在这里插入图片描述
点击New SSH key
在这里插入图片描述
添加key
在这里插入图片描述
【4】通过ssh -t 进行验证,输出如下信息表示成功。

ssh -T git@github.com  Last login: Sat Jan  6 18:32:35 on ttys000 WMBdeMacBook-Pro:~ WENBO$ ssh -T git@github.com  Hi wenmobo! You've successfully authenticated, but GitHub does not provide shell access. WMBdeMacBook-Pro:~ WENBO$  

三、配置IDEA

在终端通过where git找到git位置,再进入setting页面选择或者搜索Git并配置Path to Git executable即可。
在这里插入图片描述

四、Git基本操作

安装和配置完Git之后,你可以创建自己的代码仓库并进行基本的操作,如:
【1】使用git init初始化一个新的Git仓库。
【2】使用git add git add .来添加文件到暂存区。
【3】使用git commit -m "your message"将暂存区的改动提交到仓库。
【4】使用git push将本地仓库的更改推送到远程仓库。
【5】使用git clone 克隆一个远程仓库到本地。
【6】使用git pull将远程仓库的更改拉取到本地。

总结:Git在现代软件开发中扮演着不可或缺的角色,而macOS提供了友好和简洁的环境来支持开发者使用Git。在mac上安装、配置Git并执行基本操作是每个开发者的基础技能。无论你是一个刚入行的新手,还是一个有经验的老手,希望本文能够帮助你在mac环境下更加得心应手地使用Git

相关内容

热门资讯

2分钟辅助挂!四川徒有辅助软件... 2分钟辅助挂!四川徒有辅助软件(辅助挂)都是是真的有挂(详细辅助解密教程);1、四川徒有辅助软件透视...
2分钟细说!wepoker辅助... 2分钟细说!wepoker辅助器免费下载(辅助挂)先前是真的有挂(详细辅助可靠技巧);建议优先通过w...
第一分钟插件!边锋辅助器小程序... 第一分钟插件!边锋辅助器小程序微信(辅助挂)扑克教程(固有存在有挂)1、很好的工具软件,可以解锁游戏...
揭秘一下"新道游ap... 揭秘一下"新道游app下载"新道游app下载(切实真的是有挂);1、操作简单,无需注册,只需要使用手...
第5分钟了解!宝宝浙江辅助脚本... 第5分钟了解!宝宝浙江辅助脚本(辅助挂)真是是有挂(详细辅助教程)关于宝宝浙江辅助脚本机制的,其中提...
第8分钟了解!欢乐达人正版脚本... 第8分钟了解!欢乐达人正版脚本(辅助挂)都是真的有挂(详细辅助总结教程);1、进入到欢乐达人正版脚本...
一分钟了解!兴动互娱辅助工具名... 一分钟了解!兴动互娱辅助工具名称(辅助挂)起初是真的有挂(详细辅助细节揭秘)是一款可以让一直输的玩家...
第八分钟有挂!新西楚辅助(辅助... 第八分钟有挂!新西楚辅助(辅助挂)力荐教程(好像有挂)1、构建自己的微扑克辅助插件;2、选择您最喜爱...
重大来袭"潮汕汇软件... 重大来袭"潮汕汇软件辅助"潮汕汇软件辅助(一直是有挂)1、超多福利:超高返利,海量正版游戏,潮汕汇软...
第一分钟了解!西元文山攻略(辅... 第一分钟了解!西元文山攻略(辅助挂)总是有挂(详细辅助攻略)准备好在西元文山攻略 ia的高塔上攀登,...