提交本地项目到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    
相关推荐
小诸葛的博客2 小时前
istio如何自定义重试状态码
云原生·github·istio
MrLi01042 小时前
在git中同时配置gitcode和github访问权限
git·github·gitcode
小怪兽会微笑2 小时前
如何上传github(解决git的时候输入正确的账号密码,但提示认证失败)
git·github
松哥_ai自动化5 小时前
从抓包GitHub Copilot认证请求,认识OAuth 2.0技术
github·copilot
qianmoQ13 小时前
GitHub 趋势日报 (2025年07月15日)
github
handsomestWei13 小时前
GitHub Jekyll博客本地Win开发环境搭建
github·jekyll·blog博客·windows开发环境
DogDaoDao15 小时前
GitHub开源轻量级语音模型 Vui:重塑边缘智能语音交互的未来
大模型·github·音视频·交互·vui·语音模型·智能语音
一小池勺17 小时前
🚀 Git 如何让文件存在于远程仓库却不被本地追踪?
git·github
小华同学ai17 小时前
惊喜! Github 10k+ star 的国产流程图框架,LogicFlow 能解你的图编辑痛点?
前端·后端·github
mortimer17 小时前
为 Index-TTS 打造一个开箱即用的 Windows 整合包:从环境隔离到依赖难题的解决
人工智能·python·github