Introduction to

        

One-time configurations

User name

Set a name for credit when review version history.

git config –global user.name “Jane Smith”


User email

Set an email that will be associated with each history marker.

git config –global user.email “abc@example.com”

Line endings

On macOS and Linux

git config –global core.autocrlf input


On Windows

git config –global core.autocrlf true

Text editor

git config –global core.editor “nano -w”

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 un-report 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.

fatal: not a git repository

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 .git folder

List all files

ls -a


List the files inside the .git folder

ls .git

Using git - 98% of what you will do

  • Get versions of our files into repository
  • Attach a message to our files indicating what happened

Staging area

An intermediate area where a subset of the modified files can be grouped for a commit.

It helps to split up unrelated changes in your working directory into multiple, 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

Commit: take a snapshot of the changes from the staged files

git commit -m “Initial commit”

Tracking changes

Let’s create a file called README.md.

nano README.md


Let’s type some text into the README.md file

## Notes for UN Report 
We plotted life expectancy over time.

We can verify the file was indeed created by running

ls


We can also view the content of the file in the command line window by running

cat README.md

Commit the changes

git status


git add README.md


git status

Commit the changes

git commit -m “Start notes on analysis”


git status

Make some more changes

nano README.md


Let’s add a second line into the README.md file

## Notes for UN Report 
We plotted life expectancy over time.
Each point represents a country.


cat README.md

Commit the new changes

git status


git diff


git add README.md

Commit the new changes

git commit -m “Add information on points”


git status

Exercise

Follow the previous examples to

  • Add a third line to the README.md file
## Notes for UN Report 
We plotted life expectancy over time.
Each point represents a country.
Continents are grouped by color.
  • Commit the above change.

Question

Which of the following commit messages would be most appropriate for the last commit?

  1. “Changes”
  2. “Added line ‘Continents are grouped by color.’ to README.md”
  3. “Describe grouping”


Source: https://xkcd.com/1296/

Show the commit logs

git log


git log -5


git log –oneline

Create repository in GitHub

  • Open the GitHub website and sign in
  • Create a new repository with name un-report
    • Do not check the box to add a README file
    • Do not select a .gitignore file
    • Do not select a LICENSE file
  • Click Create repository button

Connect GitHub to your computer

  • Copy the URL that ends with un-report.git

Connect GitHub to your computer

  • Add this GitHub repo we just created as a “remote” for our local git repo.

git remote add [alias] [the url you just copied]

By convention the GitHub repo is often named origin.

git remote add origin https://github.com/x/abc.git

Create Personal Access Token

Click your GitHub profile, then “Settings”.

Create Personal Access Token

Click “Developer settings” at bottom of the left panel.

Create Personal Access Token

Click “Token (classic)”.

Create Personal Access Token

Create Personal Access Token

Create Personal Access Token

Connect GitHub to your computer

  • Where asked for your password, paste the Personal Access Token.
  • We shouldn’t be asked for password again for 90 (or whatever) days.

How to get our local repo up to GitHub?

git push origin main

GitHub changes

GitHub commit history

GitHub diffs

Let’s create a file on GitHub

Let’s create a file on GitHub

Let’s create a file on GitHub

Let’s create a file on GitHub

Let’s create a file on GitHub

Let’s commit changes on GitHub

New file already on GitHub

How do we get our file back to our local computer?

git pull origin main

Exercise

  • Create a new Git repository on your computer called workshop.
  • Write three lines about what you have learned about Python and bash a file called README.md, commit your changes.
  • Modify one line, add a fourth line.
  • Display the differences between its updated state and its original state.
  • Push it to GitHub.