A.1 Git

Cheat Sheet

Cheat Sheet in different languages

Learn Git

Interactive Cheat Sheet

Ultimate Guide of Git and GitHub for R user

  • Setting up Git: git config with --global option to configure user name, email, editor, etc.

  • Creating a repository: git init to initialize a repo. Git stores all of its repo data in the .git directory.

  • Tracking changes:

    • git status shows the status of the repo

      • File are stored in the project’s working directory (which users see)

      • The staging area (where the next commit is being built)

      • local repo is where commits are permanently recorded

    • git add put files in the staging area

    • git commit saves the staged content as a new commit in the local repo.

      • git commit -m "your own message" to give a messages for the purpose of your commit.
  • History

    • git diff shows differences between commits

    • git checkout recovers old version of fields

      • git checkout HEAD to go to the last commit

      • git checkout <unique ID of your commit> to go to such commit

  • Ignoring

    • .gitignore file tells Git what files to ignore

    • cat . gitignore *.dat results/ ignore files ending with “dat” and folder “results”.

  • Remotes in GitHub

    • A local git repo can be connected to one or more remote repos.

    • Use the HTTPS protocol to connect to remote repos

    • git push copies changes from a local repo to a remote repo

    • git pull copies changes from a remote repo to a local repo

  • Collaborating

    • git clone copies remote repo to create a local repo with a remote called origin automatically set up
  • Branching

    • git check - b <new-branch-name

    • git checkout master to switch to master branch.

  • Conflicts

    • occur when 2 or more people change the same lines of the same file

    • the version control system does not allow to overwrite each other’s changes blindly, but highlights conflicts so that they can be resolved.

  • Licensing

    • People who incorporate General Public License (GPL’d) software into their won software must make their software also open under the GPL license; most other open licenses do not require this.

    • The Creative Commons family of licenses allow people to mix and match requirements and restrictions on attribution, creation of derivative works, further sharing and commercialization.

  • Citation:

    • Add a CITATION file to a repo to explain how you want others to cite your work.
  • Hosting

    • Rules regarding intellectual property and storage of sensitive info apply no matter where code and data are hosted.