Collaborative Workflows (with Git)

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

10 Terms

1
New cards

Version Control Refresher

In term 1 we saw how a version control tool called git helps to provide resilienceĀ 

  • Git repositories (repos) are typically stored on a server somewhereĀ 

  • Repos are then cloned onto other computers as needed (e.g. your laptop)Ā 

  • All changes made within a repo are automatically tracked

  • When we have made some useful change (fix a bug, add a new featureā€¦), we commit

  • As frequently as we like we push those commits back to the serverĀ 

  • As frequently as we like we pull changes into our local repo from the serverĀ 

  • All versions of your code are stored, so no work is ever truly lostĀ 

2
New cards

Accessing a Repository for the First Time

Once there is a remote repo, we often want a local copy to work onā€¦Ā 

  • There is a standard command line tool called git

  • There are also GUI tools, and VS Code integration

  • The command line tool provides more control over your work, so is good to learn

  • We recommend you learn the command line tool in this course

  • To take a local copy of a git repo, we use the git clone command:

<p>Once there is a remote repo, we often want a local copy to work onā€¦&nbsp;</p><ul><li><p><span>There is a standard command line tool called git</span></p></li><li><p><span>There are also GUI tools, and VS Code integration</span></p></li><li><p><span>The command line tool provides more control over your work, so is good to learn</span></p></li><li><p><span>We recommend you learn the command line tool in this course</span></p></li><li><p><span>To take a local copy of a git repo, we use the git clone command:</span></p></li></ul><p></p>
3
New cards

Accessing a Private Repository

  • If your repository is private, you need to provide your credentials

  • It is recommended providing an access token as the password

  • Access tokens are similar to passwords, except you can limit access to resources, select a limited role, and provide an expiry date

4
New cards

What Git Does

Once you have a local repo, your computer is tracking ALL changes you make in that folder

  • New filesĀ 

  • Deleted files

  • Changed filesĀ 

Your local copy will not change by itself ā€“ even if someone else updates the remote repo

  • You can trust the local files no to change

  • You can trust that ANY changes you make locally will not irrevocably affect others

  • You can trust that any code that has been committed can never be truly destroyed as long as the repo exists

5
New cards

Adding New Files

If you create a new file in a repo, this will be noticedĀ 

  • But it will not automatically become part of the repo

  • Do this explicitly

  • Once added, the files content will be tracked for changes

  • Therefore, only add files you want to be tracked

  • Use "git status" to show untracked files, and changes in tracked files

  • Use "git add" to add a newly created file to a repo

<p>If you create a new file in a repo, this will be noticed&nbsp;</p><ul><li><p><span>But it will not automatically become part of the repo</span></p></li><li><p><span>Do this explicitly</span></p></li><li><p><span>Once added, the files content will be tracked for changes</span></p></li><li><p><span>Therefore, only add files you want to be tracked</span></p></li><li><p><span>Use "git status" to show untracked files, and changes in tracked files</span></p></li><li><p><span>Use "git add" to add a newly created file to a repo</span></p></li></ul><p></p>
6
New cards

Committing Changes

When you reach a good "checkpoint" commit your changesĀ 

  • E.g. fixed a bug, added a new featureā€¦Ā 

  • Keep commits clean (one meaningful code change per commit)Ā 

  • Choose a name for a commit that describes the changeĀ 

  • Commit often and include as much detail as necessary

  • Review changes before you commit. Did you intend to make all those changes??

<p>When you reach a good "checkpoint" commit your changes&nbsp;</p><ul><li><p><span>E.g. fixed a bug, added a new featureā€¦&nbsp;</span></p></li><li><p><span>Keep commits clean (one meaningful code change per commit)&nbsp;</span></p></li><li><p><span>Choose a name for a commit that describes the change&nbsp;</span></p></li><li><p><span>Commit often and include as much detail as necessary</span></p></li><li><p><span>Review changes before you commit. Did you intend to make all those changes??</span></p></li></ul><p></p>
7
New cards

Sharing Changes

Once you have one or more local commits, you can share back to the server

  • This makes your changes visible to othersĀ 

  • It also means your work is properly backed upā€¦Ā 

  • Until you push, you are still vulnerable to local loss hardware fail, theft, damage, accidental deletionā€¦Ā 

Use git push to propagate your commits back to the server

  • We specify where to push to (normally "origin" ā€“ wherever you cloned from) and the branch to push (the "main" branch is fine for now!)

<p>Once you have one or more local commits, you can share back to the server</p><ul><li><p><span>This makes your changes visible to others&nbsp;</span></p></li><li><p><span>It also means your work is properly backed upā€¦&nbsp;</span></p></li><li><p><span>Until you push, you are still vulnerable to local loss hardware fail, theft, damage, accidental deletionā€¦&nbsp;</span></p></li></ul><p>Use git push to propagate your commits back to the server</p><ul><li><p><span>We specify where to push to (normally "origin" ā€“ wherever you cloned from) and the branch to push (the "main" branch is fine for now!)</span></p></li></ul><p></p>
8
New cards

Receiving Changing

You can receive updates from others via explicitly merging them into your local repo

  • Changes only arrive when you want them to

  • Use git pull to do this

  • Any commit you don't have are then downloaded and merged into your local repo.Ā 

Unless both you and someone else have editing the same file since you last pulled, no user intervention is neededā€¦Ā 

If the version on the server is newer than your local version, you will be required to perform a pull operation before you can push

<p>You can receive updates from others via explicitly merging them into your local repo</p><ul><li><p><span>Changes only arrive when you want them to</span></p></li><li><p><span>Use git pull to do this</span></p></li><li><p><span>Any commit you don't have are then downloaded and merged into your local repo.&nbsp;</span></p></li></ul><p>Unless both you and someone else have editing the same file since you last pulled, no user intervention is neededā€¦&nbsp;</p><p>If the version on the server is newer than your local version, you will be required to perform a pull operation before you can push</p>
9
New cards

Ignoring Changes

  • We might need to keep some files only in our local repository (e.g. .class files)

  • You can configure Git to ignore such files

  • Create a .gitignore file in your local repository's root directory to tell Git which files and directories to ignore when you make a commit

<ul><li><p><span>We might need to keep some files only in our local repository (e.g. .class files)</span></p></li><li><p><span>You can configure Git to ignore such files</span></p></li><li><p><span>Create a .gitignore file in your local repository's root directory to tell Git which files and directories to ignore when you make a commit</span></p></li></ul><p></p>
10
New cards

Merge Conflicts

If someone else has updated file on the server as you have edited locallyā€¦Ā 

  • This is called a merge conflictĀ 

  • Git will need some help from you to resolve this

  • Any files in conflict will be updated with BOTH copies of lines of code that differ

  • Fix this conflict by ether choosing the versions of the lines you want

  • Or by editing the code until it is correct

  • Then add these changed files that were in conflict and commit

<p>If someone else has updated file on the server as you have edited locallyā€¦&nbsp;</p><ul><li><p><span>This is called a merge conflict&nbsp;</span></p></li><li><p><span>Git will need some help from you to resolve this</span></p></li><li><p><span>Any files in conflict will be updated with BOTH copies of lines of code that differ</span></p></li><li><p><span>Fix this conflict by ether choosing the versions of the lines you want</span></p></li><li><p><span>Or by editing the code until it is correct</span></p></li><li><p><span>Then add these changed files that were in conflict and commit</span></p></li></ul><p></p>