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

Getting Started with Git

Getting Started with Git

A hands-on presentation on Git & Github Basics.

Two tasks for the learner:
1. Fork and clone a Public Repo. Make changes and issue a PR
2. Create and update your own repo's on Github

Ram Narasimhan

February 05, 2020
Tweet

More Decks by Ram Narasimhan

Other Decks in Technology

Transcript

  1. Goals for Today 1. Learn Git Concepts and Terminology 2.

    Create/log into Github Account 3. Use Command Line (another option is the Github GUI or VSCode Github extension) Activity 1: Interacting with a Common Repo 4. Fork, and Clone a public Repo 5. Push to Remote. And issue a Pull Request (PR) Activity 2: Working with your own repositories 6. Create a New Repo (for your own use) 7. Add, commit, Push to your Repo
  2. How many of you: Have a Github Account? Have Forked

    and Clone Public Repos Have issued a PR to another person’s Repo Use Github for your own coding? Would like to learn all of the above?
  3. Fact: You can get by with just 6 git commands

    If you know 10 git commands, you are an ‘expert’
  4. Repo Repository A Git repository is a virtual storage of

    your project. It allows you to save versions of your code, which you can access when needed. Technically, a Git repository is the .git/ folder inside a project. This repository tracks all changes made to files in your project, building a history over time.
  5. How to get hold of a popular (or public repo)?

    1. You can bring a copy to your own Github account 2. Then you can bring that copy to your laptop/computer
  6. Did you note that there are two remote repos? Upstream

    (the official one) Origin (your copy on the cloud)
  7. Sending your code changes to the remote repos Reverse the

    journey. Local → Remote Remote is also referred to as the origin repo
  8. > git push origin master Send all of my committed

    changes to my copy of the remote repo, to the master branch destination branch
  9. Issue A PR Pull Request (A request to “pull in”

    our changes to the upstream repo)
  10. Step by Step 1. Fork the repo 2. Clone into

    your laptop/computer 3. Make changes (Edit files in the repo) 4. Add & Commit 5. Push to your remote 6. Issue a PR Detailed instructions are in the slides that follow
  11. Step 1: Fork the Repo Go to the “Original/Official” repo.

    In this case: go to: https://github.com/Ram-N/DSSG_Utilities Click the “Fork” Button. It is making a copy of this repo on your github account. After it is done, go to your Github account and verify that the repo is there!
  12. Step 2: Clone to your computer In your laptop, decide

    where you want to store the repo > cd <path to directory> to where you want to store the new repo > git clone https://github.com/<your username>/<reponame.git> Just click this! Tip: Copy the repo URL Don’t type it!
  13. Step 3: Editing files in the repo Go to the

    Repo in your laptop. Find any file that you want to edit. For example: docs/favorite_datascience_website.md Open it using your favorite editor of choice. (VS Code, or SublimeText or similar) Add one or more websites to the file, thus changing it. Save the file, and exit.
  14. Steps 4&5: Add, Commit & Push to *your repo* in

    Github > git add <filenames that you changed> > git commit -m “Changed file1. Added file 2” > git remote -v Git remote is to make sure that “remote” is pointing to your Github repo. (called Origin) > git push origin master
  15. Step 6: Issue A PR Pull Request A. Go to

    your repo on Github. B. Look for the Create Pull Request button. C. Click it and fill in the details
  16. Git commit vs Git Push Push vs. Commit Commit only

    updates your local repository. When we push changes, we’re interacting with a remote repository to update it with the changes we’ve made locally (often this corresponds to sharing the changes we’ve made with others).
  17. Three useful git commands (Try this on your git terminal

    now!) > git status > git log > git remote -v
  18. Make some changes & Push back to Github > git

    add <filename that you changed> > git commit -m “Changed file1. Added file 2” > git remote -v Git remote is to make sure that “remote” is pointing to your Github repo. (called Origin) > git push origin master
  19. Intermediate git stuff (Not for today, but you should try

    these anyway) • Git branches • Git checkout • Push to a specific branch • Git Merge • Delete the ‘bugfix’ branch, once it has served its purpose. We can try and arrange an Intermediate git workshop, if there is interest.
  20. True or False? We only need to git add a

    file once per project. (Once it is added, it is part of the repo)
  21. What is the missing step > git add *.py >

    ______________ > git push origin master
  22. Contact Everyone should know git! If you want this workshop

    (or the intermediate level git workshop) given to your group, just get in touch! Let’s find a suitable forum and make it happen. [email protected] @ramnarasimhan Ray Bell @RayBell_RC