Skip to content

Instantly share code, notes, and snippets.

@stephlocke
Last active April 1, 2019 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save stephlocke/5ee27c36a2942ad696cb215b32cca692 to your computer and use it in GitHub Desktop.
Save stephlocke/5ee27c36a2942ad696cb215b32cca692 to your computer and use it in GitHub Desktop.
Work with git! πŸŽ“=πŸ’ͺ
title author date
Working with Git
Steph Locke
15 September 2018

Source control fundamentals

Source control concepts

Source control is a system for tracking changes to files over time.

What's the point?

  • No version hell
  • Why did I do that?
  • Satisfy auditors
  • UNDO, UNDO, UNDO!!

What techs are there?

  • Central systems like SVN
  • Distributed systems like Git
  • Hybrid systems like TFS

Why GitHub?

  • Git is awesome
  • Public / private models
  • Great UX
  • Great integrations

Gists

What are gists?

Gists https://gist.github.com is source control without the git being obvious.

Upload or write one or more files and let it track changes for you. You can share gists and folks can fork them and change their copy.

These have git under the hood so you can see what changes were made and when, and even work with a gist locally if you want.

Exercise

  1. Google for some git resources
  2. Create a gist that contains a GitHelp.md file
  3. Add the links you found using the format:
# Git links
- [description](url)
- [description](url)
  1. Navigate to https://gist.github.com/stephlocke and fork my latest gist
  2. Add resources you found, to your copy of my gist

Git

Distributed working

With Git, we keep an online (remote) version of our projects (repository). This is the source of truth and folks can take copies of this version to work on things. They can often also install based on the code online.

We take a copy (clone) of the remote version and make our changes to it. We can be making lots of changes independently of everyone else.

Once we've made changes we're happy with, we can confirm locally they're OK by saying which things you changed are worth keeping (add). Then we can say why we changed these files (commit) so that we get a record of what changed, when, and why.

Once we've got some changes locally that we're happy with, we need to send our code (push) back to the online copy. This makes our code available to everyone else.

If someone has made some changes since we took our copy, we might need to integrate their changes into our copy. We do this by getting the updates (pull) from the online copy.

If we have been working on the same lines of code as others have, then we need to decide how our code gets combined (merge conflict). Once we've incorporated the changes, we then need to confirm we're happy (add and commit) and then send (push) our sorted version to the online copy.

git model

Git glossary

  • Repository: Your project and it's history
  • Remote: The (TFS/GitHub/VSO etc) server
  • Clone: Take a linked copy of a repository
  • Fork: Take an unlinked copy of a repository
  • Pull: Update your copy of a repository
  • Add: Include a file in a change
  • Commit: Make the latest state of all the added files the new default state
  • Push: Update the central copy of the repository with your commits

Many of these words become commands we can use in the command line, or will be the names for buttons in our GUIs.

git clone https://url/repo.git
git add file.md
git commit -m "Important bcoz πŸ›"
git push

Learning resources

Getting setup

Install

Register

Config

  • Local info
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Exercises

  1. Make a repository on github with a README
  2. Use the online editor to add some info into the README file.
    • Must include a gif ![alt text](gifurl)

Working with git

Working by yourself

When working mostly by ourselves, it can be ok to use a very simple workflow that just helps keep our code associated with why we've made changes. So long as we don't mind risking commiting broken code to our core codebase online, our workflow can be pretty simple.

git clone https://url/repo.git
# make some changes using IDE to file.md
git add file.md
git commit -m "Important bcoz πŸ›"
git push

Exercises

  1. Get a local copy
  2. Open folder in VS Code
  3. Change the gif
  4. Commit your change
    • Use emoji in your commits!
  5. Push to github

Working with others (including yourself)

If folks are installing from our online copy and we're making changes that they either shouldn't be getting yet or we're not quite certain of, then we probably need to put our code somewhere else.

How we do this in git is by adding a space we can work on our code in (branch). We can then keep track of all our changes (commit) and once we're happy with all our code, we can then add everything back into the core version (merge).

atlassian branch image

If we want to be extra safe, we could take our own full copy of the code (fork) before working on things so we can't screw up our important copy.

GitHub etc. gives us an extra safety mechanism for when we want to make changes either via a working space (branch) or a seperate copy (fork) that enables code review and approval processes. This is a pull request, frequently shortened to PR, where all our changed code can be discussed reviewed and changed. Once people are happy, the code can then be accepted (merge) into the core version (or even a branch).

Sponge fork graphic

Exercises

  1. Online, change the gif to something different
  2. Locally, change the gif to something different
  3. Push your local change
    • You should get an error
  4. Pull the online changes
  5. Fix the merge conflict and commit the change
  6. Push to github

Working on a website

This is an extended exercise to get your comfortable with working with git.

Fork the repo https://github.com/sourcethemes/academic-kickstart and follow the README instructions to get a local copy.

Navigate to netlify and make a new site with your github repo. Give it a better name. Now everytime we make a change to our repo it'll deploy automatically.

Add this new url to the first line of the config.toml file. Give it some seconds and refresh your website to see what impact your change had.

Now start, making some changes to the values in the various files. If you installed Hugo, you can use hugo serve to see changes locally as you make them.

You should have a WIP website about yourself that you can use to build up your skills and your portfolio.

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment