7.5: Git and GitHub
- Page ID
- 467083
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)Git is a Versioning Control System you can run on your computer that allows you to back up files, track changes and revert to older versions by creating a Git Repository (Repo). Within Git you can add your files to a staging area and once you are ready you can commit them to the local repository (Repo), which is in a hidden .git folder. This creates a hash string to identify each version and allows you to access them later, and compare versions. You can also push them to a remote repository, of which GitHub is the most common, and the one we will be using in this class. Figure \(\PageIndex{1}\) is a shematic showing this interaction.
![clipboard_ea2c6903df6d5992652de764f56e735f7.png](https://chem.libretexts.org/@api/deki/files/466358/clipboard_ea2c6903df6d5992652de764f56e735f7.png?revision=1)
If you wish to use Git you will need to install it on your computer, and if you wish to post material to GitHub or sync your local Git repo with GitHub you will need to create an account on GitHub, but you can access files and download content from a public GitHub without having an account, and we will be posting code at the following GitHub repo, https://github.com/rebelford/S2024_PhysComp-REPO.
Git
To install Git go to https://git-scm.com/ and install the appropriate version for your operating system. As always, you can surf the web for tutorials and YouTube if a useful place to find them, but be aware that Git, like any software, is always being updated and so the interface will evolve over time. There are three common ways to use Git, on the command line, through an integrated IDE (Interactive Development Environment) like Visual Studio or PyCharm, or through GitHub Desktop.
To install Git go to the downloads page ( https://git-scm.com/downloads ) and install for your operating system. To see what version you have go to the command line and type
git --version
GitHub Desktop
GitHub Desktop is ideal for students who are not used to the command line and one of the things I like about it is that itallows you to open any local Git Repository to Visual Studio, Windows Explorer and GitHub. The following YouTubes are pretty good; (Deborah Kurata (Clips 10-13) and Cameron McKenzie, but go out and find your own tutorials and if you find you like you can make a hypothes.is annotation using the tags physical-computing and github-desktop, and I can add them to the site later.
![clipboard_e89b6f51f95bc06f06aabd72b52bb61b9.png](https://chem.libretexts.org/@api/deki/files/466359/clipboard_e89b6f51f95bc06f06aabd72b52bb61b9.png?revision=1)
Please note, this is just an introduction to GitHub Desktop and further information can be found in the GitHub Desktop section of the IOST library.
Visual Studio
Like GitHub Desktop we have a section of the IOST library devoted to Visual Studio, which is an IDE you should install for multiple reasons. Once again you should explore the web, look for tutorials and post them to hypothes.is using the tags phys-comp and vs-code. Note, on VD-code you can install Git-Bash on the terminal and run command line commands from VS-code. The advantage is that it allows you to use Linux commands on a Windows machine, and so the command line commands you need to run your Raspberry Pi will also work here. See Using Git in VS Code (Official Beginner Tutorial).
Command Line
We are probably not going to be using the command line very much as this is an introductory class, but a quick view of the commands may also be the best way to understand Git and GitHub. I am also including common commands here as a reference point, because as you gain skills you will want to use the command line.
command syntax | function |
git init | creates a hidden .git file and transforms current directory into a git working directory, note, do not nest these. |
git add <filename> | places the current file into the staging area so you can commit it (this step is skipped in GitHub Desktop) |
git add . | the dot allows you to move all files from working directory to staging area |
git status | tells status of staging area |
git commit -m"message" | commits files from staging area to repo - you need to add a message |
git log | see commits |
git checkout <filename> | moves file from local Repo to working directory |
git remote add <name> <url> | creates remote repo (on github defined by url), typically use <name> as "origin" |
git push -u origin main | pushes local repo to remote using -u switch and sets as main branch |
touch .gitignore | creates the git ignore file that allows you to specify files not to be synced with remote see github for gitignore |
git clone <url> | clones remote to your machine |
git branch <branch-name> | creates a branch (you need to do this if you want to clone someone elses stuff) |
git branch | shows you branches |
GitHub