为NumPy开发设置git

要提供代码或文档,首先需要

  1. 计算机上安装了git

  2. GitHub帐户

  3. 叉子

安装GIT

您可能已经拥有git;请键入 git --version . 如果安装了,你会看到 git version 2.11.0 . 如果你看到 command is not recognizedcommand not found 等等。, install git .

然后设置您的姓名和电子邮件:

git config --global user.email you@yourdomain.example.com
git config --global user.name "Your Name"

创建GitHub帐户

如果您没有GitHub帐户,请访问https://github.com/join创建一个。

创建NumPy fork

Forking 有两个步骤——访问GitHub在您的帐户中创建fork repo,然后在您自己的机器上复制它。

创建fork repo

  1. 登录您的GitHub帐户。

  2. NumPy GitHub home .

  3. 在页面的右上角,单击 Fork

    ../../_images/forking_button.png

    你会看到的

    ../../_images/forking_message.png

    然后,您将被带到您的分叉副本的主页:

    ../../_images/forked_page.png

制作本地副本

  1. 在要创建副本的目录中,运行:

    git clone https://github.com/your-user-name/numpy.git
    

    你会看到的

    $ git clone https://github.com/your-user-name/numpy.git
    Cloning into 'numpy'...
    remote: Enumerating objects: 12, done.
    remote: Counting objects: 100% (12/12), done.
    remote: Compressing objects: 100% (12/12), done.
    remote: Total 175837 (delta 0), reused 0 (delta 0), pack-reused 175825
    Receiving objects: 100% (175837/175837), 78.16 MiB | 9.87 MiB/s, done.
    Resolving deltas: 100% (139317/139317), done.
    

    目录 numpy 在您的计算机上创建。(如果您已经有一个numpy目录,GitHub将选择一个不同的名称,如 numpy-1 .)

    $ ls -l
    total 0
    drwxrwxrwx 1 bjn bjn 4096 Jun 20 07:20 numpy
    
  1. 说出你的名字 upstream 到主NumPy回购:

    cd numpy
    git remote add upstream https://github.com/numpy/numpy.git
    
  2. 设置存储库以便 git pull 拉扯 upstream 默认情况下:::

    git config branch.master.remote upstream
    git config branch.master.merge refs/heads/master
    

仔细看看

  1. 所示的分支 git branch -a 将包括

    • 这个 master 你刚刚在自己的机器上克隆的分支

    • 这个 master 从GitHub上的fork分支,git将其命名为 origin 默认情况下

    • 这个 master 在你命名的主NumPy回购上的分支 upstream .

    master
    remotes/origin/master
    remotes/upstream/master
    

    如果 upstream 不是吗,它会在你访问NumPy repo之后添加,比如 git fetchgit pull .

  2. 回购协议 git remote -v show 将包括您在GitHub上的fork和主回购:::

    upstream    https://github.com/numpy/numpy.git (fetch)
    upstream    https://github.com/numpy/numpy.git (push)
    origin      https://github.com/your-user-name/numpy.git (fetch)
    origin      https://github.com/your-user-name/numpy.git (push)
    
  3. git config --list 将包括:

    user.email=your_email@example.com
    user.name=Your Name
    remote.origin.url=git@github.com:your-github-id/numpy.git
    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
    branch.master.remote=upstream
    branch.master.merge=refs/heads/master
    remote.upstream.url=https://github.com/numpy/numpy.git
    remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
    

可选:设置SSH密钥以避免密码

克隆numpyfork repo不需要密码,因为它读取远程repo而不更改它。不过,稍后提交拉取请求时,会向它写入请求,GitHub会请求您的用户名和密码——尽管这是您自己的repo。您可以通过 setting up SSH keys .

如果你在克隆之前设置了密钥 ,以上说明略有变化。而不是::

git clone https://github.com/your-user-name/numpy.git

跑步:

git clone git@github.com:numpy/numpy.git

而不是表现出 https 网址, git remote -v 将显示:

origin  git@github.com:your-user-name/numpy.git (fetch)
origin  git@github.com:your-user-name/numpy.git (push)

如果你已经克隆了 要开始使用SSH,请参阅 Switching remote URLs from HTTPS to SSH .