VERSION CONTROL AND GIT 1 / 23 PROBLEM SCENARIO 1: WORKING ALONE - - PowerPoint PPT Presentation

version control and git
SMART_READER_LITE
LIVE PREVIEW

VERSION CONTROL AND GIT 1 / 23 PROBLEM SCENARIO 1: WORKING ALONE - - PowerPoint PPT Presentation

VERSION CONTROL AND GIT 1 / 23 PROBLEM SCENARIO 1: WORKING ALONE How do you keep track of changes, and different versions of your work? 2 / 23 SOLUTION? 3 / 23 PROBLEM SCENARIO 2: WORKING IN A TEAM "My changes got overwritten!"


slide-1
SLIDE 1

VERSION CONTROL AND GIT

1 / 23

slide-2
SLIDE 2

PROBLEM SCENARIO 1: WORKING ALONE

How do you keep track of changes, and different versions of your work?

2 / 23

slide-3
SLIDE 3

SOLUTION?

3 / 23

slide-4
SLIDE 4

PROBLEM SCENARIO 2: WORKING IN A TEAM

"My changes got overwritten!" "You weren't supposed to change that le." etc.

4 / 23

slide-5
SLIDE 5

SOLUTION?

Go with the ow, and hope nothing breaks? Send emails: “Okay, I'm going to work on A.java, so don't touch it"?

5 / 23

slide-6
SLIDE 6

PROBLEM SCENARIO 3: MOVING AROUND (PRE-COVID PROBLEM?)

After a hard day of work on a DH lab computer, you want to go home and do some work at home in the evening.

6 / 23

slide-7
SLIDE 7

SOLUTION?

Copy all the les to your home machine Issues: potentially slow depending on your le sizes, you might overwrite something you did at home but forgot to copy from home to school, etc.

7 / 23

slide-8
SLIDE 8

A REAL SOLUTION

8 / 23

slide-9
SLIDE 9

VERSION CONTROL

9 / 23

slide-10
SLIDE 10

VERSION CONTROL

Keeps code in a central location ("repository") This is the master copy To make changes to it, you can create a local copy of the repository in your account at school, on your machine at home, on your laptop…

10 / 23

slide-11
SLIDE 11

COMMITTING

When the local copy changes, "commit" and "push" the changes to the repository.

11 / 23

slide-12
SLIDE 12

SOLUTION TO PROBLEM SCENARIO #1: TRACKING CHANGES WHILE WORKING SOLO

When you get something working, commit the changes Tools allow you to revert to a previous version Write good log messages so that you don't have to remember what changed in each version

12 / 23

slide-13
SLIDE 13

SOLUTION TO PROBLEM SCENARIO #2: WORKING IN A TEAM

Each team member has their own version of the code When a team member makes changes, they can commit their code to the central git repository Other team members can pull the changes from the central repository to their local machines and make their own changes, etc.

13 / 23

slide-14
SLIDE 14

SOLUTION TO PROBLEM SCENARIO #3: MOVING AROUND

A remote git repository can be accessed from anywhere! As long as you always remember to commit and push your most recent changes, you can go to any other machine and clone a local copy of the repository using a URL to your remote repository

14 / 23

slide-15
SLIDE 15

COMMON GIT COMMANDS FOR GETTING THE FILES FROM A REMOTE REPOSITORY

Clone the repository located at <repo> into the folder called <directory> on the local machine.

You will now have all the les from the repository available locally. You will typically use this once (per machine). Do not clone the same repo

  • ver and over.

Next time you want to get the most recent version of the remote repo les, just use the command "git pull".

git clone <repo> <directory>

15 / 23

slide-16
SLIDE 16

COMMON GIT COMMANDS FOR MAKING CHANGES TO A REMOTE REPOSITORY

After making changes to one of these les, you should use the following commands to keep the remote git repo synchronized with your local copy:

16 / 23

slide-17
SLIDE 17
  • r

Add specied <le> or all edited les to a "staging area". This tells Git that you want to include updates to a particular le in the next commit. (Note: This command does not actually change anything! You have to commit your changes rst.)

git add <file> git add --all

17 / 23

slide-18
SLIDE 18

This command captures a snapshot of the project's currently staged changes; you should always provide some sort of message along with a commit to make it easier to keep track of what changes were just made. This commits your changes to your local git repository.

git commit -m "<message>"

18 / 23

slide-19
SLIDE 19

Lastly, in order to synchronize your local repo with the remote repo, you must remember to git push. It's a common mistake to commit but forget to push, which means none of your team members working at different locations would be able to see the changes you committed!

git push

19 / 23

slide-20
SLIDE 20

MANAGING CONCURRENCY

20 / 23

slide-21
SLIDE 21

WHAT IF TWO (OR MORE) PEOPLE WANT TO EDIT THE SAME FILE AT THE SAME TIME?

21 / 23

slide-22
SLIDE 22

WHAT IF TWO (OR MORE) PEOPLE WANT TO EDIT THE SAME FILE AT THE SAME TIME?

Make sure you're working on the most up-to-date version (git pull will get you the most recently committed versions of all the repo les)

21 / 23

slide-23
SLIDE 23

WHAT IF TWO (OR MORE) PEOPLE WANT TO EDIT THE SAME FILE AT THE SAME TIME?

Make sure you're working on the most up-to-date version (git pull will get you the most recently committed versions of all the repo les) Then, edit the le you want to edit

21 / 23

slide-24
SLIDE 24

WHAT IF TWO (OR MORE) PEOPLE WANT TO EDIT THE SAME FILE AT THE SAME TIME?

Make sure you're working on the most up-to-date version (git pull will get you the most recently committed versions of all the repo les) Then, edit the le you want to edit Once you're done editing, try to "git commit" and "git push"

21 / 23

slide-25
SLIDE 25

WHAT IF TWO (OR MORE) PEOPLE WANT TO EDIT THE SAME FILE AT THE SAME TIME?

Make sure you're working on the most up-to-date version (git pull will get you the most recently committed versions of all the repo les) Then, edit the le you want to edit Once you're done editing, try to "git commit" and "git push"

If someone else edited that same le, two things might happen

21 / 23

slide-26
SLIDE 26
  • 1. DIFFERENT PARTS OF THE FILE WERE EDITED:

Git is smart enough to deal with that on its own, and will auto merge your les, so both sets of changes get committed to the repository.

22 / 23

slide-27
SLIDE 27
  • 2. THE SAME PARTS OF THE FILE WERE EDITED DIFFERENTLY BY MORE THAN ONE PERSON

This is where you're going to have a scary merge conict! Git will let you know that there is a conict, mark the conicting area for you in the le with <<<<<< ===== and ====== >>>>>> symbols surrounding it. You can now open up the le where a conict is found, look for those symbols, choose which of the conicting changes you want to keep, delete the symbols, and then re-commit and push.

(Video example of this: ) https://www.youtube.com/watch? v=__cR7uPBOIk

23 / 23