Skip to content

Latest commit

 

History

History
248 lines (182 loc) · 7.69 KB

File metadata and controls

248 lines (182 loc) · 7.69 KB

Part 1, Session 1 - Git and GitHub



Wait, why are we talking about Git and GitHub?

  • At a minimum, you'll need to "git clone" this GitHub repository for your use in this series
  • It's good to know about how team software development works, and how Git and GitHub fit into it
  • You'll want to use Git and GitHub for your own projects
  • Development teams (including PMs) can share files related to their projects
  • It's a foundational technology for software and AI development







Preamble

  • There are some things we don't think about much with modern technology
    • They just work, but they're amazing and complex
    • Like, how do cell phones work?
    • Like, how does the Internet work?
    • Like, how do we coordinate the changes of many people working concurrently on the same codebase?
    • Git was created by Linus Torvalds for the development of Linux
      • To more easily manage the many contributions by a worldwide Dev Team
      • It just works, beautifully
      • It is so much better that what came before it (CVS, SVN, VSS, Panvalet, etc.)
      • Most of "the cloud" runs on Linux, btw







What is Git?

  • Git is a distributed and modern Source Control System (DSCM)
  • It allows multiple developers to work on the same codebase concurrently
  • It does not use a locking model
  • It has some amazing merge functionality
  • It creates versions of each file, with incremental changes
    • Allows you to revert to a previous version of the code
    • Allows you to see a diff of the changes between two versions of the code
  • GitHub is a cloud-based PaaS (platform as a service) for Git
    • GitLab, BitBucket, and others
  • Git can be used locally on your workstation without GitHub
  • The .gitignore file
    • Is used to specify the files and paths that shouldn't be stored in git
    • secrets, passwords, URLs, credentials, etc.
    • binary files produced in the compilation and build process
    • output files from the execution of the program
    • the python virtual environment directory
  • Branches
    • The main branch is deployed to production
    • Developers create feature branches then merge these changes into the main Branch
    • You can rebase a feature branch to catch it up with the main branch
  • Pull Requests (i.e. - PRs)
    • Area peer requests to review and merge a feature branch into the main branch
    • There are many ways to do this - approver lists, workflows, CI/CD DevOps, etc.
    • This is out-of-scope for this series







Installation

This is required for this series, so that you can clone the Series GitHub repository.







GitHub Account Creation







Configuration on your Workstation/Laptop

After git is installed, configure your user.name and user.email in Windows PowerShell or macOS Terminal.

git config --help 

git config --list 

git config --global user.name  "Jane Smith"
git config --global user.email "jane.smith@gmail.com"







Authentication







Git Commands

See the docs for more information on the following commands.

This Git Cheat Sheet is a useful reference.

  • git help - create a new branch
  • git clone - copy a remote repository to your local machine
  • git ls-files - see a list of the files in the repository
  • git status - see the status of the repository
  • git pull - fetch and merge changes from a remote repository
  • git push - push changes to a remote repository
  • git checkout - switch to a different branch
  • git commit - commit changes to the repository

Cloning a Repository, and keeping it up to date

These are the only git commands you'll need to do in this series.

First, copy the remote GitHub repository to your local machine

git clone https://github.com/cjoakim/zero-to-AI.git

Then, keep it up-to-date each week

I plan on updating the repository each week, on Mondays, with new content for the next week's sessions.

git reset --hard             # This abandons your current pending changes; resets git to the last commit
git pull                     # This fetches and merges changes from the remote repository

Creating a Branch

This is for your information only; you won't have to do this in this series.

cd  <github project root directory>
git checkout main                      # navigate to the main branch of development
git pull                               # pull the latest code from GitHub
git branch cj-8822                     # create a local branch (a feature branch, JIRA item 8822) for your work
git checkout cj-8822                   # change to that local branch
git push -u origin cj-8822             # push that branch to the remote repository

... edit with the code on your local machine ...

git add <file>
git commit -m "A description of the changes"
git push                               # push the committed local changes to the remote repository

... work with the code on your local machine some more ...

git add --all
git commit -m "A description of the changes"
git push                               # pushes the committed local changes to the remote repository

Then optionally create a "Pull Request" in the GitHub UI to request a peer review and approval. There are many ways to do this - approver lists, workflows, CI/CD DevOps, etc. This is out-of-scope for this series.







GitHub Desktop UI







Pro Tip: Aliases I use

  • Added to ~/.bash_profile (macOS) or Windows 11 Profile as functions
  • gb = what branch am I on?
  • gls = list files in the repository
  • gs = git status
  • gup = git pull, reset, gc, branch
  • gurl = get the remote origin url
alias gb='git branch'
alias gls='git ls-files'
alias gs='git status'
alias gup='git status ; git reset --hard ; git pull ; git gc ; git branch'
alias gurl='git config --get remote.origin.url'

Windows PowerShell Profile Functions

function gb {
    git branch
}

function gls {
    git ls-files
}

function grh {
    git reset --hard
}

function gs {
    git status
}

function gup {
    git status ; git reset --hard ; git pull ; git gc ; git branch
}

function gurl {
    git config --get remote.origin.url
}




References







Home