Skip to content

git and GitHub FAQ

goldy edited this page Jul 15, 2020 · 11 revisions

Frequently Asked Questions about git and GitHub

Ask a question by creating a new topic or post on the DiscussCESM forums!

Current List of Answered Questions

Question: How can I clone someone's git clone to my directory on the same machine?

Answer: git clone <path_name> [<local_dir>] where <path_name> is the location of the source git clone and the optional <local_dir> is the name of the clone (default is a local directory of the same name as the original).

Question: How can I clone someone's git clone to my directory on a different machine?

Answer: git clone ssh://<user>@<machine>:<path_name> [<local_dir>] where <user> is your user name on the remote machine, <machine> is the machine name (e.g., cheyenne.ucar.edu), <path_name> is the location of the source git clone on the remote machine, and the optional <local_dir> is the name of the clone (default is a local directory of the same name as the original).

Question: How can I look at someone's PR code?

Answer: There are a few ways to do this.

  • On GitHub (like looking at any other code on GitHub)
  • Add the PR fork to my remote (allows using tools such as git diff or git difftool with your existing branches or cam_development)
  • As a clone (standalone clone on your machine).

A first step is to find the link to the fork's branch. Just below the PR is a line that starts with a colored oval (e.g., "Open" in green) and looks something like:

Octocat wants to merge 123 commits into ESCOMP:cam_development from Octocat:amazing-new-feature

Clicking on the last part (Octocat:amazing-new-feature) will take you to the correct branch where you can browse the code (the first method above). If you want to download that code, click the green "Code" button and then click the clipboard icon. Be sure to take note of the branch name.

    git remote add octocat https://github.com/octocat/CAM.git
    git fetch --no-tags octocat
    git checkout octocat/amazing-new-feature

Instead of the checkout, you can also do diffs:

    git difftool origin/cam_development octocat/amazing-new-feature
  • If you want to make a new clone with the PR code, simply do:
    git clone -b amazing-new-feature octocat https://github.com/octocat/CAM.git octocat_cam
    cd octocat_cam