使用Git上传项目到github仓库

Git 是一个免费的开源 分布式版本控制系统,旨在快速高效地处理从小型到大型的所有项目。

Git

创建本地文件夹

在 此文件下 打开 bash

右键 -> 更多

两种打开界面,看你喜欢那一款。

  1. 先打开 windows 终端 ,再 在更多下选择Git Bash ,cd 到指定目录
    alt text

  2. 直接 open git bash here

alt text

基础配置

1
2
3
4
5
6
7
8
9
// git 设置用户名与邮箱:
git config --global user.name [自定名]
git config --global user.email [邮箱]

// 查看信息
git config -l
git config --system --list
git config --global --list

配置ssh服务,关联github

还在 git bash 执行 。
bash 比之 powershell 有着linux命令操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 1.检查本地主机是否已经存在ssh key

cd ~/.ssh

ls

//看是否存在id_rsa id_rsa.pub文件

// 2.不存在 则 生成ssh密钥

ssh-keygen -t rsa -C [刚才添加的邮箱]

cd ~/.ssh

cat id_rsa.pub
//复制生成的全部内容[即密钥]

登录github->点击头像->settings->SSH and GPG keys->Add/New SSH key
粘贴保存

检验连接,执行

1
2
3
4
ssh -T git@github.com  
// 首次可能登录github,输入密码。
出现Hi xxx! You've successfully authenticated,but GitHub does not provide shell access.
表示连接成功

其他配置

设置 Git 的全局 HTTP 代理 以7890端口举例

1
2
git config --global http.proxy http://127.0.0.1:7890 
git config --global https.proxy http://127.0.0.1:7890

在 HTTPS 端口使用 SSH

创建个config文件 在./ssh下 (win+r 输入 %HOMEPATH%快速访问)

详情链接

Git 命令

alt text

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
git init   //初始化  生成了个 .git  隐藏文件夹


git status // 查看状态


git reflog // 查看提交历史


git add . // 添加文件到暂存区


git commit -m "first commit" // 更改提交


git remote add origin git@github.com:xfk215/zua-oj-2023.git // 关联github 仓库


git remote -v // 查看当前配置的远程仓库地址


git push -u origin main // 推到 github 加载到 100% ok

后面再用 , 执行

eg: 修改了 1.md 文件

1
2
3
4
5
6
7

git add 1.md

git commit -m "second commit" 1.md

git push -u origin main

其他

  1. 初始化仓库

    1
    git init
  2. 克隆远程仓库

    1
    git clone [url]
  3. 查看当前状态

    1
    git status
  4. 添加文件到暂存区

    1
    git add [file]
  5. 提交更改到本地仓库

    1
    git commit -m "commit message"
  6. 查看提交历史

    1
    git log
  7. 查看更改的文件

    1
    git diff
  8. 查看历史记录的图形化界面

    1
    gitk
  9. 查看当前分支

    1
    git branch
  10. 创建新分支

    1
    git branch [branch-name]
  11. 切换到指定分支

    1
    git checkout [branch-name]
  12. 创建并切换到新分支

    1
    git checkout -b [branch-name]
  13. 合并分支

    1
    git merge [branch-name]
  14. 推送本地更改到远程仓库

    1
    git push origin [branch-name]
  15. 拉取远程更改

    1
    git pull origin [branch-name]
  16. 设置远程仓库

    1
    git remote add origin [url]
  17. 查看远程仓库

    1
    git remote -v
  18. 删除远程分支

    1
    git push origin --delete [branch-name]
  19. 删除本地分支

    1
    git branch -d [branch-name]
  20. 重命名分支

    1
    git branch -m [old-branch-name] [new-branch-name]
  21. 查看所有分支的合并情况

    1
    git branch -a
  22. 拉取远程分支并创建本地分支

    1
    git fetch origin [branch-name]:[local-branch-name]
  23. 解决合并冲突

  • 手动编辑冲突的文件。
  • 使用 git add 将解决后的文件添加到暂存区。
  • 使用 git commit 提交解决冲突后的更改。
  1. 撤销工作目录中的未暂存更改

    1
    git checkout -- [file]
  2. 查看已跟踪文件的更改

    1
    git diff [file]
  3. 重置暂存区,取消暂存文件

    1
    git reset HEAD [file]
  4. 查看配置信息

    1
    git config --list
  5. 设置全局配置

    1
    2
    git config --global user.name "[name]"
    git config --global user.email "[email address]"
  6. 设置跟踪文件的换行符

    1
    git config --global core.autocrlf input
  7. 查看帮助文档

    1
    git help [command]

the end