Git Primer

Installation

  1. Install Git

  2. Use a command line terminal

  3. Make an SSH key

  4. Add your SSH key to GitHub account

Windows

  1. Download and install from here: https://git-scm.com/download/win

  2. Use the included Git Bash application as a command line interface to Git.

  3. Make an ssh key as outlined here:

  4. Add SSH Key to GitHub Account Guide

MacOS

  1. Use one of the methods outlined here to install Git: https://phoenixnap.com/kb/install-git-on-mac

  2. Use the Terminal app to interface with Git.

  3. Make an ssh key as outlined here:

  4. Add SSH Key to GitHub Account Guide

Linux

  1. Install the git package with your distribution’s package manager; for example on Ubuntu:

    sudo apt install git
    
  2. Use any terminal app to interface with Git.

  3. Make an ssh key as outlined here:

  4. Add SSH Key to GitHub Account Guide

GitHub Desktop

On Windows and Mac, GitHub offers a graphical application called GitHub Desktop as an alternative to the command line interface for Git.

See here: https://desktop.github.com/

Using Git

Here we’ll cover some of the basic commands from the command line. See More Git Resources for more extensive tutorials.

git clone

Grab a copy of a repository from the URL provided.

$ git clone git@github.com:Smithsonian/cfa-git-users.git
Cloning into 'cfa-git-users'...
remote: Enumerating objects: 90, done.
remote: Counting objects: 100% (90/90), done.
remote: Compressing objects: 100% (50/50), done.
remote: Total 90 (delta 29), reused 78 (delta 22), pack-reused 0
Receiving objects: 100% (90/90), 616.79 KiB | 8.12 MiB/s, done.
Resolving deltas: 100% (29/29), done.
$ ls .
cfa-git-users

git status

View the statius of the repository.

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified:   git-primer.rst
deleted:    github.rst
modified:   index.rst
modified:   si-org.rst

Untracked files:
(use "git add <file>..." to include in what will be committed)
git-github.rst

no changes added to commit (use "git add" and/or "git commit -a")

git add

Stage a file to be comitted.

$ git add git-github.rst
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file:   git-github.rst

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified:   git-primer.rst
deleted:    github.rst
modified:   index.rst
modified:   si-org.rst

git commit

Commit a snapshot of the files.

$ git commit -m "update docs"
[main 5fd9f1e] update docs
4 files changed, 116 insertions(+), 8 deletions(-)
rename docs/{github.rst => git-github.rst} (100%)

git pull

Update your local directory with the contents from the remote repository. ::

$ git pull
Already up to date.

git push

Send your local changes to the remote repository.

$ git push
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 16 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 2.08 KiB | 1.04 MiB/s, done.
Total 6 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To github.com:Smithsonian/cfa-git-users.git
b57a6fc..5fd9f1e  main -> main

git log

Show a log of the previous commits.

$ git log --oneline
5fd9f1e (HEAD -> main, origin/main, origin/HEAD) update docs
b57a6fc add note on front page
f79ecfe more updates
7097b47 add a couple images
ead1c28 don't use cache
43096ed update requirements
6083458 update docs
baaeda2 use furo theme, update si-org page
6a8adb7 add .gitkeep files
bea5821 Update README.md
3ec6262 flatter dir structure
61f11c8 some structure and github deploy action
6fc244b skeleton of documentation
d9d9889 Initial commit

git help

Show help for a command.

$ git help

More Git Resources