Quick Introduction of Git

2019-02-01

Sam Tomioka

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency 

Scott Chacon and Ben Straub. 2014. Pro Git (2nd ed.). Apress, Berkely, CA, USA.

Overview of GIT

  • Git is local
  • GitHub is remote
  • Share with others
  • Access other repositories
  • Backup for local repository

Tools

Use Git Bash 1

Register your user name and email.

git
$ git config  --global user.name 'Sam Tomioka'
$ git config  --global user.email 'sam.tomioka@sunovion.com'

Use Git Bash 2

Confirm your config file

git
$ git config  --list

Authenticate with GitHub

curl -H 'Authorization: token <MYTOKEN>'

MYTOKEN is your token. See GitHub Documentation how you can create your token.

Create GitHub Repo

Start from scratch

Fork another repo

Clone the repo

  • Copy to local repo, so you can contribute.
  • First, get the URL

  • Navigate to a specific folder in your local system, then
    git
    $ git clone https://github.com/stomioka/sdtm_mapper

Check local repo

$\leftarrow$

Create your branch

  • To create
git
$ git branch your_branch
  • To confirm
git
$ git branch

Pull Requests

  • To merge in your changes into other branch/repo
  • Send a pull/merge request from Github to the owner of the repository

Pull Requests From Other Users

  1. Updates made in Forked Repo: Fork and Pull Model
    • Anyone can fork, update the objects
    • Changes can be pulled into the source by the project maintainer
  1. Updates made within the same Repo: Shared Repository Model
    • The owner of the repo can add collaborators via GitHub account email address
    • Team van review pull requests, before changes can be pulled into the source.

Demo

  1. Create a new object
  2. Add to Index (Staging Area)
    • git add . adds all new files.
    • git add -u updates tracking for files that changed names or were deleted
    • git add -A does both of the above
  3. Commit to local repo
    • git commit -m 'your message'
      • -m to add message.
      • Alternatively, use Vi text editor. :wq! to save the message and clode Vi text.
  4. Push to remote repo
    • git add master or git add your-branch
  5. Go to your branch or master
    • git checkout your-branch
    • git checkout master