{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Git and Github" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What is git?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Git is a tool for version control that allows you to track changes so that you can work collaboratively in a team environment. A lot of software developers and engineers use it but scientists also use it to maintain their software/code generated for research. Although I will cover some basics on using Git, you will need to read up on what it is and how to use it at your own time. See here for more information:\n", "\n", "https://guides.github.com/introduction/git-handbook/\n", "\n", "Here is another resource on Git. It is for Bitbucket repository but command examples are the same as what you would be using with Github.\n", "\n", "https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to install Git" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, you will try to install `git` tool through command line tools such as Homebrew on Mac.\n", "\n", "On **Mac OS**, you will type like this in your terminal: `brew install git`\n", "\n", "On **Windows OS** running **Linux** subsystem with **Ubuntu**, you can type something like this in your terminal: `apt-get install git`\n", "\n", "However, if you have installed Homebrew on WSL, you may be able to just type the same command as it is for Mac OSs. \n", "\n", "And this will install the tool on your command line environment. You may need root privileges to install tools on Ubuntu. If this happens, you just type: `sudo apt-get install git` and it should work. You will have to type your password though.\n", "\n", "Another way of installing `git` is to use your Miniconda package managing system. It is actually my preferred method of installing new tools in my commandline environment. If you have set up Miniconda correctly, then you can just type:\n", "\n", "`conda install git` in either Mac or Windows OS terminal and this would install `git` on your system. Here is an example of what you will see when you use Miniconda to search if git is in its list of packages that you can install through `conda` command." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading channels: ...working... done\n", "# Name Version Build Channel \n", "git 2.12.2 4 conda-forge \n", "git 2.13.3 0 conda-forge \n", "git 2.14.1 0 conda-forge \n", "git 2.14.1 1 conda-forge \n", "git 2.14.1 pl526ha558ef4_2 pkgs/main \n", "git 2.14.1 pl526hcdafd81_2 pkgs/main \n", "git 2.14.2 0 conda-forge \n", "git 2.14.2 1 conda-forge \n", "git 2.14.2 2 conda-forge \n", "git 2.14.2 3 conda-forge \n", "git 2.15.0 pl526h6165b5f_0 pkgs/main \n", "git 2.16.1 h74bb3f6_0 pkgs/main \n", "git 2.16.1 pl526h74bb3f6_1 pkgs/main \n", "git 2.17.0 pl526h028e6c8_0 pkgs/main \n", "git 2.17.1 0 conda-forge \n", "git 2.17.1 pl526h028e6c8_0 pkgs/main \n", "git 2.18.0 0 conda-forge \n", "git 2.18.0 pl526h028e6c8_0 pkgs/main \n", "git 2.18.0 pl526hbb17d3c_1 conda-forge \n", "git 2.19.0 pl526hbb17d3c_0 conda-forge \n", "git 2.19.1 pl526h028e6c8_0 pkgs/main \n", "git 2.19.1 pl526h28b1069_1000 conda-forge \n", "git 2.19.1 pl526h28b1069_1001 conda-forge \n", "git 2.19.1 pl526h6951d83_0 pkgs/main \n", "git 2.19.1 pl526hbb17d3c_0 conda-forge \n", "git 2.19.1 pl526hbb17d3c_1 conda-forge \n", "git 2.19.2 pl526h28b1069_1000 conda-forge \n", "git 2.19.2 pl526hbb17d3c_0 conda-forge \n", "git 2.20.0 pl526h28b1069_1000 conda-forge \n", "git 2.20.0 pl526hbb17d3c_0 conda-forge \n", "git 2.20.1 pl526h28b1069_1000 conda-forge \n", "git 2.20.1 pl526h28b1069_1001 conda-forge \n", "git 2.20.1 pl526h3e3e3d1_1002 conda-forge \n", "git 2.20.1 pl526h6951d83_0 pkgs/main \n", "git 2.20.1 pl526hbb17d3c_0 conda-forge \n", "git 2.21.0 pl526h3e3e3d1_0 conda-forge \n", "git 2.22.0 pl526hbdf3604_0 conda-forge \n", "git 2.23.0 pl526h6951d83_0 pkgs/main \n", "git 2.23.0 pl526hbdf3604_0 conda-forge \n", "git 2.23.0 pl526hbdf3604_1 conda-forge \n", "git 2.23.0 pl526hbdf3604_2 conda-forge \n", "git 2.24.0 pl526hdc91d69_0 conda-forge \n", "git 2.24.0 pl526hdc91d69_1 conda-forge \n", "git 2.25.0 pl526hdc91d69_0 conda-forge \n", "git 2.26.0 pl526h561ab23_0 conda-forge \n", "git 2.26.1 pl526hcc376a2_0 conda-forge \n", "git 2.26.2 pl526hcc376a2_0 conda-forge \n", "git 2.27.0 pl526hcc376a2_0 conda-forge \n", "git 2.28.0 pl526hde3ca24_0 conda-forge \n", "git 2.28.0 pl526hde3ca24_1 conda-forge \n" ] } ], "source": [ "%%bash\n", "conda search git" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What can you do with `git` and Github?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Github allows you to create either private or public repositories that are version-controlled, meaning that each changes you made to an original file or document has versions that you can choose to keep or discard. \n", "\n", "For example, if you have a new file named `text.txt` which created and you want to make it part of a repository, you will need to type the command `git add text.txt`. You may type this command in the folder that this file is located or from the root folder. If it is in a subfolder named jsaw/notes/text.txt, then you want to type git add jsaw/notes/text.txt in the root folder.\n", "\n", "After adding the file, you will need to type the following command.\n", "\n", "`git commit -a`\n", "\n", "It will bring up the vim editor, which will prompt you to enter a message before you can commit this file to the repository. If you would rather bypass this step, you can specify in your previous git command like this:\n", "\n", "`git commit -m \"created a new file\"`\n", "\n", "Here, you have put in quotes the text you wanted to convey along with the commit command to let people know that you have created a new file and added it to the repository. This helps your teammates and collaborators keep track of what you did to the repository.\n", "\n", "Finally, type `git push origin master` to \"push\" your changes to the repository.\n", "\n", "Before committing or pushing anything to the repository, you should always type `git pull origin master` to get the latest updated version of the repository. This is because there is a built-in check for people to prevent overwriting things or missing something if someone else had made a very recent commit to the repository. \n", "\n", "**Note:** We will discuss how to create your own repositories later in the semester." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" } }, "nbformat": 4, "nbformat_minor": 4 }