class: center, middle # Introduction to .center[![:scale 30%](./images/Git-Logo-2Color.png) ] .center[![:scale 30%](./images/GitHub_Logo.png)] --- class: middle, center ![:scale 56%](./images/phd101212s.gif) .tiny[.lightgray[“Piled Higher and Deeper” by Jorge Cham]] --- class: middle, center ![:scale 100%](./images/git-branch.svg) --- class: middle, center # One-time configurations --- ### User name Set a name that is identifiable for credit when review version history. ``` $ git config --global user.name "Fred Feng" ``` -- ### User email Set an email address that will be associated with each history marker. ``` $ git config --global user.email "fredfeng@umich.edu" ``` --- # Line endings ### On macOS and Linux: ``` $ git config --global core.autocrlf input ```
### On Windows: ``` git config --global core.autocrlf true ``` --- ### Default Branch name ``` $ git config --global init.defaultBranch main ``` -- ### Credential storage ``` $ git config --global credential.helper store ``` -- ### View the configurations ``` $ git config --list ``` --- # cd into your directory To check if you are there, print the working directory ``` $ pwd ```
Or you can list the files in the current directory ``` $ ls ``` --- # Show the status of the git repository ``` $ git status ``` At this point, we will see an error message. This is because the directory is not a git repository yet. --- # Initialize a new Git repository ``` $ git init ``` --- # Show the status of the git repository ``` $ git status ``` - Show modified files in working directory, staged for your next commit. --- # Under the hood Git stores all project info inside a hidden .red[.git] folder List all files ``` $ ls -a ```
List the files inside the .red[.git] folder ``` $ ls .git ``` --- # Staging area An intermediate area where a subset of the modified files can be grouped for a commit. .center[![:scale 90%](./images/git-committing.svg)] It helps to split up unrelated changes in your working directory into multiple, more meaningful commits. --- # Add files to the staging area ``` $ git add [file_1] [file_2] ``` Add the files (as they look now) to the staging area for your next commit. - Each commit should be a logical unit of change. --- # Commit (i.g., take a snapshot of) the changes from the staged files ``` $ git commit -m "Some meaningful commit message" ``` --- Let's create some initial files. - `analysis.py` - `notes.md` - `/figures` --- # Commit the changes ``` $ git status ``` ``` $ git add [file_1] [file_2] ``` ``` $ git status ``` ``` $ git commit -m "Initial commit" ``` ``` git status ``` --- class: middle, center # Tracking changes --- # Make some changes Lets make some changes to the plot and add a line to the notes. --- # Commit the new changes ``` $ git status ``` ``` $ git diff ``` ``` $ git add [file_1] [file_2] ``` ``` $ git commit -m "Add information on points" ``` ``` $ git status ``` --- # Exercise Follow the previous examples to - make some additional changes to the plot - add some notes - commit the above change - check the commit log --- Which of the following commit messages would be most appropriate for a commit? 1. "Changes" 1. "Added line 'Continents are grouped by color.' to notes.txt" 1. "Describe grouping" --- class: middle, center ![:scale 100%](./images/git_commit_2x.png)
.lightgray[Source: https://xkcd.com/1296/] --- # Show the commit logs ``` $ git log ``` ``` $ git log -5 ``` ``` $ git log --oneline ``` --- class: middle, center # Intro to GitHub --- - Open the GitHub website and sign in - Create a new repository - Do not check the box to add a README file - Copy the URL that ends with .red[.git] - Add this GitHub repo we just created as a "remote" for our local git repo. ``` $ git remote add [alias] [url] ``` By convention the GitHub repo is often named .red[origin]. ``` $ git remote add origin https://github.com/x/abc.git ``` --- ``` $ git clone [url] ``` ``` $ git push origin main ``` ``` $ git pull origin main ```