提交本地项目到GitHub

文章目录

  • [1 下载git](#1 下载git)

    • [1.1 通过homebrew安装Git](#1.1 通过homebrew安装Git)
    • [1.2 通过Xcode安装](#1.2 通过Xcode安装)
  • [2 创建ssh key、配置git](#2 创建ssh key、配置git)

  • [3 提交本地项目到GitHub](#3 提交本地项目到GitHub)

  • 说明:该博文参考这篇文章和这段视频

1 下载git

1.1 通过homebrew安装Git

  • 1、未安装homebrew,需安装homebrew
c 复制代码
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 2、安装git
c 复制代码
 brew install git

1.2 通过Xcode安装

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

2 创建ssh key、配置git

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

没有创建过的,会要求确认路径和输入密码,这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。

  • 3、用cat命令查看
c 复制代码
cat .ssh/id_rsa.pub
  • 4、登录GitHub(默认你已经注册了GitHub账号),点击Settings,点击New SSH key,添加ssh key

  • 5、链接验证
c 复制代码
ssh -T git@github.com 

终端输出的结果

c 复制代码
Last login: Sat Jan  6 14:42:55 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$ 

3 提交本地项目到GitHub

  • 1、在GitHub上新创建一个 repository或者Start a Project,如图:
  • 2、填写项目信息,如下图所示:

    点击Create repository,就创好一个工程了
  • 3、在终端输入cd 要上传的文件夹内,依次输入
c 复制代码
git init
git add .
git commit -m "First Commit"
  • 4、进入github中复制SSH地址
  • 5、上传到github
c 复制代码
git remote add origin 粘贴刚刚复制的SSH地址链接

或者使用

c 复制代码
git remote set-url origin 粘贴刚刚复制的SSH地址链接
  • 6、push到github
c 复制代码
git push -u origin master    
相关推荐
go54631584655 小时前
指导初学者使用Anaconda运行GitHub上One - DM项目的步骤
github
时光追逐者19 小时前
Visual Studio使用GitHub Copilot提高.NET开发工作效率
c#·github·.net·copilot·ai编程·微软技术·visual studio
油泼辣子多加1 天前
2025年02月01日Github流行趋势
github
萨文 摩尔杰1 天前
hexo部署到github page时,hexo d后page里面绑定的个人域名消失的问题
github
油泼辣子多加2 天前
2025年01月31日Github流行趋势
github
Ronin-Lotus2 天前
上位机知识篇---Git&GitHub
git·学习·github
AI悦创|编程1v13 天前
GitHub Actions定时任务配置完全指南:从Cron语法到实战示例
github
**kwargs3 天前
ssh密钥登录GitHub时一直提示“Error: Permission denied (publickey)”
运维·ssh·github
dreadp3 天前
解锁豆瓣高清海报:深度爬虫与requests进阶之路
前端·爬虫·python·beautifulsoup·github·requests
江_小_白4 天前
fatal: unable to access ‘https://github
github