本篇文章以macos为基础(windows系统同样有参考意义),介绍了git的卸载,homebrew的安装,git的安装以及利用git工具将项目代码放置github仓库。

(1)git的卸载

本人电脑很久没有用了,发现以前安装的git版本有点低了,所以决定重新安装最新的git(建议:自己学习某些工具或软件的时候可以选择它的稳定版本,因为稳定版本多数企业可能在用。或者下载最新版本试用,长江后浪推前浪,随着版本的更新功能可能会越来越完善)。

192:~ huayu$ git --version
git version 2.15.0
192:~ huayu$ which -a git
/usr/local/bin/git
/usr/bin/git
192:~ huayu$ cd /usr/local/
192:local huayu$ cd git
192:git huayu$ ls
Library     contrib     lib     share
bin     etc     libexec     uninstall.sh
192:git huayu$ sh uninstall.sh
This will uninstall git by removing /usr/local/git/, and symlinks
Type 'yes' if you are sure you wish to continue: yes
Password:
Forgot package 'com.git.pkg' on '/'.
Uninstalled
192:git huayu$ git --version
-bash: /usr/local/bin/git: No such file or directory

(2)homebrew的安装

homebrew是macos下的软件管理工具,类似redhat的yum,可以使用homebrew对软件安装、更新等操作。

//执行brew命令报如下错误,说明本机并没有安装homebrew
192:git huayu$ brew search wget
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
Error: The current working directory doesn't exist, cannot proceed.

homebrew官网:https://brew.sh/index_zh-cn

在homebrew官网有对它详细的介绍,下面开始安装homebrew

//在终端键入以下命令对homebrew安装,期间会让输入一次密码(你的机器密码),输入完毕后等待安装完成
192:git huayu$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

等待的时间可能会很长(不确定是不是本人住所网络的原因),看到如下的图说明brew安装成功了。

(3)git工具的安装

git工具有两种安装方式:

第一种,登陆git官网https://git-scm.com/下载.dmg 文件安装(windows同理)

如果点击后仍未自动下载,点击下面的链接手动下载

点击保留dmg文件,开始下载 ,等待下载完毕

不是在apple appstore下载的软件都会提示这个东西,需要在隐私里设置一下

打开后根据后续的提示一步一步安装就可以了,在这不再赘述。

第二种,采用homebrew安装git工具

经过漫长的等待安装完毕homebrew后,使用brew安装git开始。

//输入安装命令后发现brew又有更新了,需要等待一段时间
192:~ huayu$ brew install git
Updating Homebrew...
==> Installing dependencies for git: gettext and pcre2
==> Installing git dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.20.1.catalina.bot
==> Downloading from https://akamai.bintray.com/10/107d7f386fbeea6979f9376cdbbcf
########################                                                  33.9%########################                                         ########################  #########################                                                 35.5%
....
//brew 更新完毕后会自动进入git的下载
==> Installing git
==> Downloading https://homebrew.bintray.com/bottles/git-2.23.0_1.catalina.bottl
==> Downloading from https://akamai.bintray.com/cb/cb74c5f3a0e89f7415e9846f96e2d
//下载完毕后查看git版本  使用brew安装的git路径在/usr/local/Cellar/git/2.23.0_1
//由查看的git版本可以看出brew下载的也是当前官网发布的最新版本
192:~ huayu$ git --version
git version 2.23.0

(4)使用git工具上传代码到github

1)设置用户名与邮箱

192:bin huayu$ git config --global user.name "yuhua"
192:bin huayu$ git config --global user.email "17610835230@163.com"

2)设置免密

//密匙我以前已经设置过,这次再重新覆盖一次(以前如没生存则创建,生成过则覆盖)
192:bin huayu$ ssh-keygen -t rsa -C "17610835230@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/huayu/.ssh/id_rsa):
/Users/huayu/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/huayu/.ssh/id_rsa.
Your public key has been saved in /Users/huayu/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:5VoKkQi6QbTYLgfGdm3zcDMwf2WaKHbhazrZe2YfYmw 17610835230@163.com
The key's randomart image is:
+---[RSA 2048]----+
|.o.  o .   o     |
|+o....=.o =      |
|==...BoO +.      |
|o=. o B.=o       |
|o o   .+S o      |
| o    =..+       |
|     + .oE .     |
|      . ++. .    |
|       .+ ..     |
+----[SHA256]-----+

查看公钥

192:bin huayu$ cd ~/.ssh/
192:.ssh huayu$ ls
id_rsa      id_rsa.pub  known_hosts known_hosts.old
192:.ssh huayu$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRE1M0vB2xU6GdPGLzB3Z4x6PuFVlm3zYcfvfFtq+NcEIIycEGmg9DOglHD1mKlQPtf7eq+pd41m3kVRqy/sSgfNHy5yWX2NzxxaHaUlQ1w2QzKyURShXq7l/L8M6/vy9LFWqV/eEkdOofbj74LyscT0iR8KL8KagBgeSSthMp/UQeqwiCa4Uh6sqPfWKybcg+ShtGpXUprQHIMwqEApvpcvyHGh2hHBqAGmamgfQcHMzy4095tM4/0h/SSLA6UMPyVFsZ9MjP7gqL1xmoGJEwundwQoKxuF36jU3OD2zhXTuIdl2xV3dJwhwiLT9F+8xLppQ7PTZnT5gCaSLyg21l 17610835230@163.com

登陆自己的github账号,将生成的公钥复制到github设置中

title自定义输入,将刚刚生成的公钥内容粘贴到key的位置,添加一下。

验证设置是否成功

192:.ssh huayu$ ssh -T git@github.com
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Enter passphrase for key '/Users/huayu/.ssh/id_rsa':
Hi Myuhua! You've successfully authenticated, but GitHub does not provide shell access.

3)在github仓库创建代码库,下图两处都可以创建新仓库,任意选择即可

public是公开,private不公开,可自行选择,填写完毕后确认创建。

到这里项目仓库就创建成功了

4)将自己的本地项目上传到github远程仓库

对于新创建的远程仓库开始使用操作一般有两种情况:

第一种是先创建新的远程仓库,将创建的仓库克隆到本地机器,编写代码后再通过一系列git的操作将代码提交到远程仓库。

这一种我将通过借助idea代码编写工具进行演示。打开idea,克隆刚创建的github远端仓库

登陆github,可通过token的形式也可通过用户名密码的形式,本处通过用户名密码进行登陆。

登陆成功后进行远程仓库链接测试

点击test,测试通过后,点击clone,将远端仓库克隆到本地机器

一直next到finish就可以,因为此处仅做演示,不必考虑项目结构。

项目clone完毕后就在idea中打开了。

修改readme文件进行代码上传远程github仓库演示

快捷键ctrl+k,将代码提交到本地仓库

快捷键ctrl+shift+k,将代码push到远端仓库。(注意:如果快捷键不生效可能是热键冲突导致,查看一下是不是与其他软件冲突,比如输入法设置的快捷键)

点击push按钮后到github仓库查看,发现代码提交成功了。第一种情况演示到此结束。

第二种情况,本地项目已经创建好,提交到远端新创建的github仓库。在第一种情况演示的时候是通过借助idea完成,第二种情况我将采用git命令的形式做演示。

//初始化仓库(重要提示:在执行以下命令前先cd到要提交项目的目录下再进行操作)
192:ailive huayu$ git init
已初始化空的 Git 仓库于 /Users/huayu/Documents/project/ailive/.git/
//提交未跟踪和修改文件,但是不处理删除文件。将文件添加到暂存区
192:ailive huayu$ git add .
//将代码提交到本地库
192:ailive huayu$ git commit -m "first commit"
[master(根提交) 5aad17e] first commit27 files changed, 2057 insertions(+)create mode 100644 .gitignorecreate mode 100644 .mvn/wrapper/MavenWrapperDownloader.javacreate mode 100644 .mvn/wrapper/maven-wrapper.jarcreate mode 100644 .mvn/wrapper/maven-wrapper.propertiescreate mode 100644 ailive_server/.gitignorecreate mode 100644 ailive_server/.mvn/wrapper/MavenWrapperDownloader.javacreate mode 100644 ailive_server/.mvn/wrapper/maven-wrapper.jarcreate mode 100644 ailive_server/.mvn/wrapper/maven-wrapper.propertiescreate mode 100644 ailive_server/mvnwcreate mode 100644 ailive_server/mvnw.cmdcreate mode 100644 ailive_server/pom.xmlcreate mode 100644 ailive_server/src/main/java/AiliveCommonApplication.javacreate mode 100644 ailive_server/src/main/resources/application.propertiescreate mode 100644 ailive_server/src/test/java/com/example/common/AiliveCommonApplicationTests.javacreate mode 100644 ailive_web/.gitignorecreate mode 100644 ailive_web/.mvn/wrapper/MavenWrapperDownloader.javacreate mode 100644 ailive_web/.mvn/wrapper/maven-wrapper.jarcreate mode 100644 ailive_web/.mvn/wrapper/maven-wrapper.propertiescreate mode 100644 ailive_web/mvnwcreate mode 100644 ailive_web/mvnw.cmdcreate mode 100644 ailive_web/pom.xmlcreate mode 100644 ailive_web/src/main/java/com/example/ailive_web/AiliveWebApplication.javacreate mode 100644 ailive_web/src/main/resources/application.propertiescreate mode 100644 ailive_web/src/test/java/com/example/ailive_web/AiliveWebApplicationTests.javacreate mode 100644 mvnwcreate mode 100644 mvnw.cmdcreate mode 100644 pom.xml
//添加一个新的远程 Git 仓库
192:ailive huayu$ git remote add origin https://github.com/Myuhua/ailive.git
//将本地的master分支推送到origin主机,同时指定origin为默认主机,后面就可以不加任何参数使用git push了。git push 是默认只推送当前分支。
192:ailive huayu$ git push -u origin master
To https://github.com/Myuhua/ailive.git! [rejected]        master -> master (fetch first)
error: 推送一些引用到 'https://github.com/Myuhua/ailive.git' 失败
提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 'git pull ...')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
//用上一种方式演示的仓库再用于本次属于更新了,这样就导致了两本部分的冲突,报了以上的错误,删除旧仓库重新建一个再提交就可以了
192:ailive huayu$ git push -u origin master
枚举对象: 40, 完成.
对象计数中: 100% (40/40), 完成.
使用 8 个线程进行压缩
压缩对象中: 100% (27/27), 完成.
写入对象中: 100% (40/40), 51.26 KiB | 10.25 MiB/s, 完成.
总共 40 (差异 3),复用 0 (差异 0)
remote: Resolving deltas: 100% (3/3), done.
To https://github.com/Myuhua/ailive.git* [new branch]      master -> master
分支 'master' 设置为跟踪来自 'origin' 的远程分支 'master'。

到此位置,代码就上传到github远程仓库了,可登上github仓库到项目下查看确认一下。

特别提示:如果项目包全都创建完毕不要忘记在各个包内创建临时文件,否则上库后包会不显示。

【GitHub】项目代码上传github相关推荐

  1. 使用pycharm将自己项目代码上传github(保姆教程)

    1.梳理一下Git.github和gitee这三个之间的关系: 1.1.Github 首先从我们最熟悉的github来说,他其实是一个代码托管平台,我们可以在他的里面新建很多的仓库,有强迫症的我理解就 ...

  2. 将项目代码上传至svn服务器,xcode 把项目代码提交到远程SVN服务器

    环境 xcode 7  Mac air xcode默认支持GIT源码管理工具,但现在想把代码提交到已有到SVN服务器上,步骤如下: 1,在safari中打开svn链接地址,信任证书,输入用户名密码 , ...

  3. 如何将uniapp项目代码上传至gitee仓库**

    1.下载git,官网地址 git官网,一路next即可 2.安装TortoiseGit工具 官网地址:TortoiseGit官方下载地址,步骤如下: 下载完毕以后可以选择安装中文安装包 点击setup ...

  4. Android studio下将项目代码上传至github包括更新,同步,创建依赖

    AS中设置GIT 一.开篇 本文讲如何使用Android Studio将项目上传到github,虽然讲上传github的文章很多,但是大部分都是使用Git Bash命令行,虽然效率高些,但是有点麻烦, ...

  5. 超详细——入门Github的代码上传

      Github的使用与Gitee相差无几,由于网速原因,国内开发者主要使用Gitee作为版本管理器,但有些场景及项目需要用到Github,今天我将对Github的使用制作一个简单的初学者入门教程,不 ...

  6. 使用LitePal操作数据库(CRUD增删改查) 项目已上传GitHub

    GitHub项目地址: https://github.com/Skymqq/LitePalSave.git LitePal是一款开源的Android数据库框架,它采用了对象关系映射(ORM)映射的模式 ...

  7. 编写精美的聊天界面(左边显示接收消息,右边显示发送消息)(项目已上传GitHub)

    附上我的GitHub项目地址: https://github.com/Skymqq/UIChat.git 学习Android开发,了解一个精美聊天界面的实现是很有必要的,如果可以掌握这个技能,那么在下 ...

  8. RecyclerView控件实现横向滚动和瀑布流布局,以及RecyclerView的点击监听(项目已上传GitHub)

    先附上我的GitHub项目地址: https://github.com/Skymqq/RecyclerViewTest.git 我们已经知道,ListView的拓展性不好,它只能实现纵向的滚动的效果, ...

  9. git 项目代码上传到服务器上,git 上传代码到服务器

    一.建立本地git仓库 1.cd到你项目根目录下 git init 二.将本地所有文件添加到暂存区 git add . . 表示所有文件 如果想添加项目中的指定文件,那就把.改为指定文件名或者目录即可 ...

最新文章

  1. BZOJ 1927 星际竞速
  2. 47 APScheduler安装及基本概念
  3. 10年程序员总结的20几条经验教训
  4. PHP快速排序(原地切分)
  5. Linux Vim 光标错位,技术|Vim 复制粘帖格式错乱问题的解决办法
  6. int char转换成string java,java中int,char,string三种类型的相互转换
  7. 【长沙集训】2017.10.28
  8. c语言3到7位水仙花数流程图_C语言入门基础整理
  9. Leetcode120.三角形的最小路径和 -- DP算法
  10. Shelld5的使用
  11. 简单图像灰度化处理python代码
  12. 马翔:联想双态IT 助力企业IT新变革
  13. springSecurity分离资源服务器分析
  14. HTML5 基础入门教程
  15. 美团点评 2019校园招聘 后台开发方向职位编程题-2018.09.06
  16. 短语匹配-match_phrase以及slop参数
  17. 表空间的相关查询命令
  18. qt 获取当前程序运行路径_Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法...
  19. 离线安装VS2019教程
  20. 2022年必须知道的数字化转型!

热门文章

  1. 有了这6个东西之后,学Python还愁学不成?楼下大爷都入门了
  2. 阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
  3. 蓝牙查看接收到GIF格式的图片报错问题
  4. 绝地求生亚服服务器维护,绝地求生大逃杀亚服服务器在哪 进入亚服方法
  5. js 动态调用 applet 内的方法
  6. linux发音,官方标准
  7. Python模块和包的介绍(模块含义、用模块好处、模块分类、包和模块的创建)
  8. Java基础50题(1) 1~10题
  9. 从Palantir上市看智能决策平台发展前景
  10. 数据查询和业务流分开_索格非SOGEFI:EDI 业务场景详解之生成DESADV