DEV Community

xtofl
xtofl

Posted on • Edited on

Set up Trainig a Distributed Git Workflow on a Single Computer

Context

Imagine a pandemic.

You're suddenly forced to work from home. Network resources are scarse, but you want to be able to train your distributed git skills.

There are a ton of resources out there:

But don't you need a git server and some separate computers to do all that?

Well, good news: for the bulk of the skills, you can go with a setup on a single PC that allows a single person to mimic the real thing quite well.

And here's a way you can create a disposable sandbox to start training.

Prerequisites

  • git command line client is installed on your system

The Setup

I want to fake a central repository and two members in the team: me (Alice) and someone else (Bob). (I don't mind role plays)

We want an Authorative Repository to push to and pull from. And we want to have some clones we can do some work in.

And since this should be a sandbox, you want to be able to throw everything away and start from scratch.

Instructions

  1. Create a sandbox folder (mkdir sandbox; cd sandbox)
  2. Create an authorative repository (git init --bare central.git)
  3. Be Alice: clone the central (git clone central.git alices-clone)
    1. git clone central.git alices-clone
    2. cd alices-clone
    3. git config user.name Alice; git config user.email alice@sandbox
    4. cd ..
  4. Be Bob: clone the central
    1. git clone central.git bobs-clone
    2. cd bobs-clone
    3. git config user.name Bob; git config user.email bob@sandbox
    4. cd ..

There you go. Now all is left: playing around. And then, throwing all away and starting over. That's what sandboxes are for.

(Note: depending on the system, you may need to allow users to push to the central. TBI).

Playing Around

Here's Bob.

PS C:\Users\krpi\sandbox> git clone .\central.git\ bobs-clone; cd bobs-clone
PS C:\Users\krpi\sandbox\bobs-clone> git config user.name Bob; git config user.email bob@sandbox
PS C:\Users\krpi\sandbox\bobs-clone> echo "Do read me" >> README.txt
PS C:\Users\krpi\sandbox\bobs-clone> git add .\README.txt
PS C:\Users\krpi\sandbox\bobs-clone> git commit -m "Add readme"
[master (root-commit) b29fe43] Add readme
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.txt
PS C:\Users\krpi\sandbox\bobs-clone> git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 280 bytes | 140.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To C:/Users/krpi/sandbox/.\central.git\
 * [new branch]      master -> master
Enter fullscreen mode Exit fullscreen mode

And there is Alice.

PS C:\Users\krpi\sandbox> git clone .\central.git\ alices-clone; cd alices-clone
Cloning into 'alices-clone'...
done.
PS C:\Users\krpi\sandbox\alices-clone> git config user.name Alice; git config user.email alice@sandbox
PS C:\Users\krpi\sandbox\alices-clone> git checkout -b alices-branch
Switched to a new branch 'alices-branch'
PS C:\Users\krpi\sandbox\alices-clone> echo "I am Alice" >> hello.txt
PS C:\Users\krpi\sandbox\alices-clone> git add .\hello.txt; git commit -m "Say hello"
[alices-branch b66072d] Say hello
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 hello.txt
PS C:\Users\krpi\sandbox\alices-clone> git push -u origin alices-branch
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 372 bytes | 186.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To C:/Users/krpi/sandbox/.\central.git\
 * [new branch]      alices-branch -> alices-branch
Branch 'alices-branch' set up to track remote branch 'alices-branch' from 'origin'.
Enter fullscreen mode Exit fullscreen mode

Hey! There's Bob again.

PS C:\Users\krpi\sandbox\bobs-clone> git fetch
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From C:/Users/krpi/sandbox/.\central.git\
 * [new branch]      alices-branch -> origin/alices-branch
PS C:\Users\krpi\sandbox\bobs-clone> git log origin/alices-branch
commit b66072d91ad8b8d8869b1eb79021d3069e1b5f30 (origin/alices-branch)
Author: Alice <alice@sandbox>
Date:   Thu Mar 19 07:25:37 2020 +0100

    Say hello

commit b29fe434df968b17da2c10d58371f50bc7200b68 (HEAD -> master, origin/master)
Author: Bob <bob@sandbox>
Date:   Thu Mar 19 07:20:00 2020 +0100

    Add readme
Enter fullscreen mode Exit fullscreen mode

Conclusion

I surely hope this wasn't scary at all. This should take away all excuses to do a little git training everyday.

Top comments (0)