Github之pull requests提交分支

This is an article that was created 509 days ago, and the information may have evolved or changed.

这篇文描述的是使用我注册的第二个Github账号对netops_v2.0_beta仓库进行一次pull requests

计划是修改代码使其在Ubuntu环境也能正常运行,然后推送分支进行pull requests

登陆Github

先fork原仓库至第二个账号(过程略),获取 Clone 链接 https://github.com/weeaster/netops_v2.0_beta.git,克隆至本地

1
2
3
4
5
6
7
8
9
kir@kir:~/my_repo/netops_v2.0_branch$ git clone https://github.com/weeaster/netops_v2.0_beta.git
Cloning into 'netops_v2.0_beta'...
remote: Enumerating objects: 67, done.
remote: Counting objects: 100% (67/67), done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 67 (delta 32), reused 51 (delta 18), pack-reused 0
Receiving objects: 100% (67/67), 42.97 KiB | 31.00 KiB/s, done.
Resolving deltas: 100% (32/32), done.
kir@kir:~/my_repo/netops_v2.0_branch$

修改代码

  • 不是重点
  • 主要内容是修改 msoffcrypto 替换 pywin32 库(原仓库已修改),修改系统的路径(左右斜杠符号)

Ubuntu本地Git

  1. 本地git config配置(免密操作git push)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    $ git config --global user.name yourusername
    $ git config --global user.email yourmail@nb.com
    $ git config --list
    user.name=username
    user.email=yourmail@nb.com
    core.repositoryformatversion=0
    core.filemode=true
    core.bare=false
    core.logallrefupdates=true
    remote.origin.url=https://github.com/weeaster/netops_v2.0_beta.git
    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
    branch.main.remote=origin
    branch.main.merge=refs/heads/main
  2. cd命令进入本地代码目录,执行git init,提示重新初始化现有Git存储库(那么智能)

    1
    2
    $ git init
    Reinitialized existing Git repository in /home/kir/my_repo/netops_v2.0_branch/netops_v2.0_beta/.git/
  3. 本地创建ssh-key(生成公钥和私钥)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    kir@kir:~/$ ssh-keygen -t ed25519 -C "yourmail@nb.com"
    Generating public/private ed25519 key pair.
    Enter file in which to save the key (/home/kir/.ssh/id_ed25519):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/kir/.ssh/id_ed25519
    Your public key has been saved in /home/kir/.ssh/id_ed25519.pub
    The key fingerprint is:
    SHA256:xxxxxx
    The key's randomart image is:
    +--[ED25519 256]--+
    ……
    ……
    +----[SHA256]-----+
  4. Github网站添加SSH keys(基操)

    ScreenCaputure230429024711

  5. 测试

    1
    2
    3
    4
    5
    6
    7
    kir@kir:~/my_repo/netops_v2.0_branch/netops_v2.0_beta$ ssh -T git@github.com
    The authenticity of host 'github.com (20.205.243.166)' can't be established.
    ED25519 key fingerprint is SHA256:xxxxxx
    This key is not known by any other names
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
    Hi weeaster! You've successfully authenticated, but GitHub does not provide shell access.
  6. 设置远程仓库地址(https//xxxx不好使,换成git@xxxx)

    1
    2
    3
    4
    5
    $ git remote rm origin
    $ git remote add origin git@github.com:weeaster/netops_v2.0_beta.git
    $ git remote -v
    origin git@github.com:weeaster/netops_v2.0_beta.git (fetch)
    origin git@github.com:weeaster/netops_v2.0_beta.git (push)
  7. 三板斧git add,git commit,git push,推送到ubuntu-branch分支

    1
    2
    3
    4
    $ git checkout -b ubuntu-branch
    $ git add .
    $ git commit -m "ubuntu-branch push"
    $ git push origin ubuntu-branch
  8. 第7步中可能出现的插曲,原因是在github设置了Keep my email addresses private,处理步骤如下

    • 回显错误提示

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      $ git push origin ubuntu-branch
      Enumerating objects: 25, done.
      Counting objects: 100% (25/25), done.
      Delta compression using up to 4 threads
      Compressing objects: 100% (13/13), done.
      Writing objects: 100% (13/13), 1.60 KiB | 327.00 KiB/s, done.
      Total 13 (delta 8), reused 0 (delta 0), pack-reused 0
      remote: Resolving deltas: 100% (8/8), completed with 8 local objects.
      remote: error: GH007: Your push would publish a private email address.
      remote: You can make your email public or disable this protection by visiting:
      remote: http://github.com/settings/emails
      To github.com:weeaster/netops_v2.0_beta.git
      ! [remote rejected] ubuntu-branch -> ubuntu-branch (push declined due to email privacy restrictions)
      error: failed to push some refs to 'github.com:weeaster/netops_v2.0_beta.git'
    • 在github网站:http://github.com/settings/emailskeep my Email private 选项下的找到匿名 Email; 格式是:id+username@users.noreply.github.com

    • 重新设置git用户

      1
      $git config --global user.email "id+username@users.noreply.github.com"
    • 重置上次commit提交的作者信息

      1
      $ git commit --amend --reset-author
    • 再次push

      1
      $ git push origin ubuntu-branch

Compare&pull request

切换到 ubuntu-branch 分支,点击 Compare & pull request 按钮

ScreenCaputure230429033544

填写信息

ScreenCaputure230429034912

原仓库账号处理pull requests

查看pull requests

ScreenCaputure230429040401

拒绝该次pull requests

ScreenCaputure230429041738

原仓库账号创建分支

提交pull request 的账号重新本地push到一个新分支;重复Compare&pull request步骤,提交pull request时注意选择原仓库创建的分支

ScreenCaputure230429044039

同意合并

ScreenCaputure230429045452

ScreenCaputure230429045738

检查

打开Comparing查看lib/comm.py部分代码,可以看到路径的斜杠符号是左斜杠/

ScreenCaputure230429050806

最后

pull request 1

  • 知乎有个图画挺好,我画一下
  • 总体来说还行
  • 我不是搞软件的,这么一搞也就图一乐
  • 拜了个拜
  • 这篇文,不那么欢迎“来电”来函探讨
GPT问答230429 Ubuntu publickey方式SSH连接与vscode远程调试
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×