1 of 35

Beginners’

Git

with

6pm Wednesday�27th March 2024

UTS ProgSoc�Event #4

2 of 35

🏗️ Setting Up

git config --global core.editor code

3 of 35

📣 ProgSoc Announce

  • GenComm
  • Programmers’ Hangout

4 of 35

🤔 Why Git?

Git is a “version control” software, which keeps track of code changes and allows multiple people to easily work on the same codebase.

Usually there is a “main/master branch”, where team members branch off to do their work, and then merge their work back into the main/master branch.

5 of 35

Workshop Time!

6 of 35

🖼️ A Picture

Git keeps a sort of log book journal for your code.

It does this by keeping entries that track changes in your code, known as 'commits', inside a sort of database known as a 'repository'. Alongside each commit is a short description known as a 'commit message', and extra metadata such as the date, time and author.

These commits are made inside 'branches', which can peel away from the 'main' (or 'master') branch, or even other branches, to test new features, fixes or changes in a separate timeline.

7 of 35

📂 Folder Setup

  • Create a folder to put your work from the first part of tonight’s workshop:
    • Name it anything you like, but�Git2024Local will help you later.

8 of 35

🔰 Initialising Your Local Git Repository

Graphical

Command

Open the Git2024Local folder you created. Then:�Initialise Repository for VSCode, or git init in a terminal.

9 of 35

📄 Create Some Files

Graphical

Create README.md and guide.md, copying the contents from https://github.com/ProgSoc/Git2024

10 of 35

🕵️ Tracking Your First Files

Graphical

Once you’ve written to the files and saved them, stage the changes.

Command

11 of 35

🧾 Committing Your Changes

Graphical

Command

12 of 35

🦖 Checking History

Graphical

Command

13 of 35

🌿 Creating Your First Branch

Graphical

Command

14 of 35

✒️ Making a Change

Add this Git event, or your own idea for an event or project into guide.md

15 of 35

🤝 Merging Changes

Graphical

Command

16 of 35

Group Time!

17 of 35

🙂 Pick Your Groups

We’ve now got the hang of using Git locally,�but Git is also a collaborative tool!

Pick a group of 2+ people at your table,�and choose 1 to be repository ‘owner’.

Everyone should create GitHub accounts.�The owner will create a new empty repository�and add the other group members as ‘collaborators’.

>> How do I do all that? (Check the Next Slides)

18 of 35

🔑 Sign Up for GitHub 🔑

19 of 35

🍴 Forking the Workshop 🍴

20 of 35

📬️ Sharing Your Repository 📬️

21 of 35

🔐 Authenticating Git to GitHub

  • Download GitHub CLI
    • https://cli.github.com
  • On Windows open “Command Prompt”
    • C:\> gh auth login
  • On Mac or Linux open “Terminal”, or with “Git Bash” on Windows
    • ~ $ gh auth login
  • When Prompted:
    • Log into: GitHub.com
    • Protocol: HTTPS
    • Authenticate Git: Yes
    • How to Authenticate: Login with a web browser

22 of 35

🧪 Cloning the Remote (Owner’s Fork)

Graphical

Command

git clone "https://github.com/<TeamOwner>/Git2024"

23 of 35

📮 Pushing Your Own Branch

Graphical

Command

24 of 35

🤔 What is a Pull Request?

When you are ready to merge your changes into the master (old name) or main (most repos use this now) branch of your repository, you must create a new pull request.

A pull request allows other members of your team to analyse and review the changes you are making to the code, being able to add comments and provide potential improvements.

It is best practice to have your pull request approved by at least one team member before merging the code back into master to mitigate any�issues with the code or incorrect changes in functionality.

25 of 35

📎 Making a Pull Request

or

��Because this is a fork, make sure you make the PR to your repo not to the ProgSoc one

26 of 35

🤝 Merging a Pull Request

To merge the changes, press “Merge pull request” and then confirm the merge.

There are multiple types of merges, being merging, squashing, and rebasing.

27 of 35

🤔 What is a Merge Conflict?

What happens if multiple people make a change to the same line?

You get a merge conflict!

Merge conflicts show what’s your current change, what’s the incoming change (what you’re trying to merge in), and you have to resolve them.

28 of 35

Resolving a Merge Conflict

The first step is to fix it in the code. For each conflict, press “Accept Current” or “Accept Incoming” and then make sure the code is right.

After the file’s conflicts are resolved, press the + on the file to stage it.

After all the conflicting files are staged, you can commit your merge!��(If you’re in a terminal, you can pick the change you think is right�between matching <<<<<<<, +======, and >>>>>>> in the files)

29 of 35

😕 Inducing a Merge Conflict

In order to create a merge conflict (for educational reasons), do the following:

  • From main, 2 people should each create a new branch
  • Both people should make a commit, changing the same line in different ways (e.g. different date formats)
  • Both people open a pull request
  • Merge one of the pull requests
  • Observe that now you can’t merge the other pull request
  • The other person needs to run git pull origin main to update their branch, this shows the merge conflict
  • Once it’s resolved, you can push again and the second PR can be merged

30 of 35

🚀 Where to From Here?

  • git rebase�(and --interactive mode)
  • git reset
  • git stash
  • git revert
  • git bisect
  • git cherry-pick

31 of 35

Collaboration Time!

32 of 35

⚠️ Creating Issues ⚠️

If you’ve found something that needs fixing or have an idea,�but you don’t have the programmer skills yet to contribute:�Submit an issue to help keep track of it.

33 of 35

⭕️ Live Collaboration ❌�❌ Noughts & Crosses ⭕️

Copy in small, specific areas as features or fixes from the completed files�Then submit your changes via Pull Requests to the live branch on the ProgSoc repo

34 of 35

🍕 Pizza Time! 🍕

Workshop Survey

Event Timing

35 of 35

<Doing a Thing in Git/>

Graphical

Command