Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Git and Github

Introduction to Git and Github

This presentation introduces the basics of git to developers using the github platform.
After this presentation, users should be able to start using git effectively to manage and collaborate in projects

Bernard Parah

May 11, 2019
Tweet

Other Decks in Technology

Transcript

  1. Outline What is version Control System Why do you need

    to use one? Popular Web Version Control Systems Git Commands Demo Project
  2. You made a major mistake in your project, by introducing

    breaking changes and you need to revert to a working version of your code…
  3. BUGS EVERYWHERE You have made so many changes already, in

    so many files. You can’t even remember what exact changes even if you can remember all the files If you remember all, it will take you a lot of time to CTRL + Z all the mess
  4. So what is Git? ➔ An open-source project developed by

    Linux Torvalds in 2005 ➔ Git is an open-source Distributed Version Control System ➔ A command line utility Let us breakdown this seemingly complex term …. Distributed Version Control System
  5. Distributed The code is not kept on any single central

    server, it is kept on multiple computers. A loss on one computer can easily be recovered by getting the same code from another computer that is storing a copy of it. You get the full history of the project as well.
  6. Version Control System For every change made to a project,

    a new version of the project is created, this helps keep track of the state of the project at any given point in time. This keeps a history of what happened throughout the life history of the project.
  7. Why do we need git? ➔ Allow multiple developers work

    in parallel ➔ Allow developers to quickly revert to a working version of a project ➔ Different features might be built simultaneously, this introduces the concept of branching
  8. Git Structure You can imagine git as a tree structure

    and all the commands you run are to navigate or manipulate that tree. Any new commit creates a new node(leave) on the tree structure
  9. Git Structure If you understand how the Git repository is

    a tree of commits and see how operations like branching, merging, pushing, and pulling manipulate that tree, then understanding other Git commands should not be difficult.
  10. Working with Git Repositories A Repository is a data structure

    where git stores information in. A git repository is made up of: • A set of commit objects. • A set of references to commit objects, called heads.
  11. Git Structure You can imagine git as a tree structure

    and all the commands you run are to navigate or manipulate that tree. Any new commit creates a new node(leave) on the tree structure
  12. Commit Objects A commit object contains is made up of

    3 things: • A set of files, reflecting the state of a project at a given point in time. • A commit message, describing what the commit was about • An SHA1 name, a 40-character string that uniquely identifies the commit object. The name is composed of a hash of relevant aspects of the commit, so identical commits will always have the same name. commit 26a02bd03ca716949f9d819a89e35c4a9b603aff
  13. Installing Git ➔ Go to https://git-scm.com and install the version

    of your choice ➔ Configure your git setup globally to control all your git operations on the computer
  14. Git Config Set your identity, you will only need to

    do this once $ git config --global user.name "John Doe" $ git config --global user.email [email protected] You can check your settings by running: $ git config --list
  15. Create a remote git repository • Create an account on

    github.com • Create a repository
  16. Add remote url Create a file Index.txt 1. Introduce a

    change to the file 2. Introduce the change by adding it to the staging area : $ git add index.txt 3. Commit the change : $ git commit -m “made a file change” 4. Push the change : $ git pull origin master
  17. Git Init $ git init This creates a new git

    repository or converts an unversioned project into a git project. This can also be used to reinitialize a git repository back to a clean state
  18. Git add <filename1> <filename2> $ git add index.html style.css Use

    this command to add specific files that have been changed to the staging area
  19. Git add . $ git add . Use this command

    to add all files that have been made to the staging area
  20. Git Remote $ git remote add origin <repository url> Use

    this to connect the local and remote repositories
  21. Pull $ git pull origin <branch name> Use this command

    to pull remote changes from the named branch.
  22. Push $ git push origin <branch name> Use this command

    to push local changes to the named remote branch.
  23. Switch Branch $ git checkout <branch-name> Use this command to

    switch to the named branch Ps: it is best practice to commit the code on the current branch before switching
  24. Check Current Branch $ git branch This command lists all

    the branches and indicates the current branch as well
  25. Create branch and checkout $ git checkout -b <branch-name> Use

    this command to create a branch and switch to the branch
  26. Merge $ git merge <branch-name> Use this command to merge

    changes from the named branch into a single branch. This command is usually used in conjunction with GIT CHECKOUT.
  27. Fetch $ git fetch Get changes from a remote repository

    without the changes affecting your current work. This is usually a harmless form of git pull.
  28. Stash $ git stash This command creates a record of

    the current work while switching you back to the last clean working version
  29. My personal workflow usually looks like: 1. Do some programming.

    2. git status to see what files I changed. 3. git diff [file] to see exactly what I modified. 4. git commit -a -m [message] to commit.