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

Git

 Git

Git

Jussi Pohjolainen

April 14, 2020
Tweet

More Decks by Jussi Pohjolainen

Other Decks in Technology

Transcript

  1. Problem • Lost your work? • Made accidental update and

    want to go back? • Want to collabarate with other on the same files?
  2. Solutions • Local Version Control • Copy files (manually) into

    another directory • Common, simple and may result for errors • Centralized Version Control (CVS) • Collaboration with others • All files are on a single server (central place) that clients access • If server is down, we have problems • Distributed Version Control Systems (DVCS) • Your local files are mirrored to the server • If server dies, you can continue with your work • Git is a DVCS
  3. Installing • macOS • Install Xcode and Xcode Command Line

    Tools via App Store • Linux • sudo dnf install git-all • Windows • http://git-scm.com/download/win
  4. Global Settings git config --list credential.helper=osxkeychain user.name=pohjus [email protected] core.editor=code filter.lfs.smudge=git-lfs

    smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true filter.lfs.clean=git-lfs clean -- %f credential.helper=cache --timeout=3600
  5. Change Global Settings git config --global user.name "Max Power" git

    config --global user.email "[email protected]" Configure git, give name, e-mail of your choice
  6. .gitconfig cat ~/.gitconfig [user] name = Jussi Pohjolainen email =

    [email protected] [core] editor = code [filter "lfs"] smudge = git-lfs smudge -- %f process = git-lfs filter-process required = true clean = git-lfs clean -- %f [credential] helper = cache --timeout=3600
  7. GitHub • Github provides hosting for software development version control

    using git • Owned by Microsoft • Offers free plans and pro and enterprise accounts • Offers unlimited private repositories to all plans, including free accounts
  8. Software Repository • A software repository, or “repo” for short,

    is a storage location for software packages. • It is like a floder for you project • Contains all of your project's files and stores each file's revision history • You can share ownership of repository to other people
  9. Clone the repository to your computer git clone https://github.com/pohjus/shoppinglist Cloning

    into 'shoppinglist'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done.
  10. Clone the repository to your computer cd shoppinglist/ ls -al

    drwxr-xr-x 4 pohjus staff 128 Apr 13 11:11 . drwxr-xr-x 3 pohjus staff 96 Apr 13 11:11 .. drwxr-xr-x 12 pohjus staff 384 Apr 13 11:11 .git -rw-r--r-- 1 pohjus staff 32 Apr 13 11:11 README.md
  11. README.md file • The only file can be found now

    in three places • shoppinglist/README.md (working copy) • inside of .git/ folder (local repository) • In github server (server repository)
  12. Let's create new file with some content touch shopping-list.txt echo

    "- potato" >> shopping-list.txt cat shopping-list.txt - potato
  13. File States • File can be tracked or untracked •

    Untracked • git does not detect any changes to the file • Tracked • git follow if changes are made to the file
  14. Checking state: git status git status On branch master Your

    branch is up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) shopping-list.txt nothing added to commit but untracked files present (use "git add" to track) The new file is untracked!
  15. File States • Untracked • Tracked • Unmodified – no

    changes to the file since last commit • Modified – changed since last commit • Staged – ready to be committed Tracked has sub states!
  16. Changing state git add shopping-list.txt git status On branch master

    Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: shopping-list.txt Let's add tracking to the new file The state is now staged (ready for commited)
  17. Commiting to local repository git commit -m "shopping list added."

    [master f8f94d7] shopping list added. 1 file changed, 1 insertion(+) create mode 100644 shopping-list.txt
  18. Pushing to GitHub git push Enumerating objects: 4, done. Counting

    objects: 100% (4/4), done. Delta compression using up to 12 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 308 bytes | 308.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/pohjus/shoppinglist c1d4598..f8f94d7 master -> master
  19. https://www.quora.com/How-is-Git-different-from-CVS shopping-list.txt the new file was committed to here: shopping-list.txt

    the new file was committed to here: shopping-list.txt And now the repository can be found in other PC shopping-list.txt
  20. File States • Untracked • Tracked • Unmodified – no

    changes to the file since last commit • Modified – changed since last commit • Staged – ready to be committed It is not ready to be committed yet!
  21. Back to Mr Mac User: pull git pull remote: Enumerating

    objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/pohjus/shoppinglist f8f94d7..4a37b3e master -> origin/master Updating f8f94d7..4a37b3e Fast-forward shopping-list.txt | 1 + 1 file changed, 1 insertion(+)
  22. Create new file import java.util.*; class App { public static

    void main(String [] args) { List<String> items = List.of("tomato", "potato"); items.forEach(System.out::println); } }
  23. git status git status On branch master Your branch is

    up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) App.class App.java nothing added to commit but untracked files present (use "git add" to track) Do not track classes!
  24. git status git status On branch master Your branch is

    up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore App.java nothing added to commit but untracked files present (use "git add" to track)
  25. git add -A git add -A git status On branch

    master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitignore new file: App.java
  26. commit and push git commit -m "Create .gitignore and new

    Java file." [master a53b44e] Create .gitignore and new Java file. 2 files changed, 9 insertions(+) create mode 100644 .gitignore create mode 100644 App.java git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 12 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 494 bytes | 494.00 KiB/s, done. Total 4 (delta 0), reused 0 (delta 0) To https://github.com/pohjus/shoppinglist 16f8ac8..a53b44e master -> master