{git}

Source code control basics

One project, many copies

# git

GitHub

remote repo: "origin"

You

local repo
workspace

Your team mate

local repo
workspace
local repo
workspace

Your team mate

Your changes can live in several places

# git
stash
workspace
local repo
index
remote repo

Under the carpet: hide things from git

Files you are working on

Changes staged for commit

Hidden folder keeping track of commits

Online backup for sharing

Your changes can live in several places

# git
stash
workspace
local repo
index
remote repo

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>
git add Project.cs

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>
git commit -m "Change the project file in this specific way"

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>
git push origin main

We use commands to move them

# git
workspace
local repo
index
remote repo
<my changes to some files>

We use commands to move them

# git
workspace
local repo
index
remote repo
<someone else's changes>
<my changes>

We use commands to move them

# git
workspace
local repo
index
remote repo
<someone else's changes>
<my changes>
git pull

We use commands to move them

# git
workspace
local repo
index
remote repo
<someone else's changes>
<my changes>

Auto-merging time

# git
workspace
local repo
index
remote repo
<someone else's changes>
<my changes>
Merge remote-tracking branch 'origin/main'

# Please enter a commit message to explain why this merge is necessary, 
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
#       .git/MERGE_HEAD
# and try again.
# On branch main.
# Your branch and 'origin/main' have diverged,
# and have 1 and 1 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)

~

~

~

~

 

Save the default commit message

# git
workspace
Merge remote-tracking branch 'origin/main'

# Please enter a commit message to explain why this merge is necessary, 
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
#       .git/MERGE_HEAD
# and try again.
# On branch main.
# Your branch and 'origin/main' have diverged,
# and have 1 and 1 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)

~

~

~

~

:wq

Common mistakes

# git
  • Leaving your work un-pushed for ages
  • Handing in heaps of work in a single commit
  • Working on your own and "handing in" right at the end
  • Making a different repo that we don’t know about
  • Avoiding using git properly because it’s hard
  • Doing weird things to avoid merge conflicts
  • Ignoring or only skim reading error messages

Advice and pointers

# git
  • Break things, it's allowed!
  • Ask for help BEFORE you make a big mess
  • Ask for help AFTER you've read the error message properly
  • Start your own projects and practice by breaking things
  • Try to do things the proper way as per instructions - it's done that way for a reason
  • Always talk with your team before you make changes - merge conflicts are a pain
  • Avoid deleting everything and starting again until advised to do so - you might miss a great learning opportunity (ask for help!)
  • Google like a pro

git

By Elise Allen