Github基础操作

线上创建Github仓库

首次初始化

初始化

git init

添加README.md

git add README.md

添加提交描述

git commit -m "first commit"

连接远程仓库

git remote add origin https://github.com/nongshuqiner/-git-.git

提交操作

添加到本地仓库

git add .

添加提交描述

git commit -m '内容'

提交前先从远程仓库主分支中拉取请求

git pull origin master

把本地仓库代码提交

git push -u origin master

其他

从远程仓库克隆代码

git clone https://github.com/XXX/XXX.git

查看git操作记录

git status

分支

查看远程分支

git branch -a

查看本地分支

git branch

创建新分支

git branch branchName

切换到新分支

git checkout branchName

创建新分支+切换到新分支

git checkout -b branchName

合并分支

假设当前在master分支

git merge v2

v2分支合并至当前master分支

远程仓库

查看所有远程仓库


git remote

查看指定远程仓库

git remote 指定仓库地址

添加(连接)远程仓库

git remote add origin https://github.com/nongshuqiner/-git-.git

移除远程分支

git remote rm origin

PS:若修改远程仓库可先删除,再添加

git config配置

范围:

git config:当前仓库
git config --global:此计算机账号下全局
git config --system:此系统下无论账号

优先级:

git config > git config --global > git config --system

查看全局配置

git config --global --list

结果

filter.lfs.clean=git-lfs clean %f
filter.lfs.smudge=git-lfs smudge %f
filter.lfs.required=true
user.name=Yourname
user.email=XXX@email.com
core.autocrlf=false
http.postbuffer=524288000

修改全局配置(例如修改用户名)

git config --global user.name 'newname'

若报错,使用如下命令修改全局配置

git config --global --replace-all user.name 'newname'

设置SSH keys

检查是否存在SSH keys

ls -al ~/.ssh

使用SSH加密(填入注册邮箱)

ssh-keygen -t rsa -C 'zhuce@email.com'
ssh-agent -s
ssh-add ~/.ssh/id_rsa

登录Github个人中心,找到SSH and GPG keys,添加密钥。
将本地id_rsa.pub中内容复制过去。

测试是否添加成功

ssh -T git@github.com

相关文章

咱们在vscode中使用copilot的过程中,有可能会涉及到个人账号...
这篇文章给大家介绍怎么在GitHub上快速找到实用资源,内容非...
这篇文章主要介绍“github缓存穿透的解决方法是什么”,在日...
本篇内容介绍了“github线性回归怎么实现”的有关知识,在实...
怎样使用GitHub,很多新手对此不是很清楚,为了帮助大家解决...
今天小编给大家分享一下GitHub的高级搜索方法有哪些的相关知...