Bash and Git – Awesome, For You, Right Now



Bash and Git – Awesome, For You, Right Now

0 0


bgconcepts-explained

Bash and Git core concepts, explained and applied

On Github meonkeys / bgconcepts-explained

Bash and Git

Awesome, For You, Right Now

by Adam

Quiz

What is Bitcoin?

I aim to empower you, challenge you, and inspire you to learn more.

(quick poll: prior shell/Git experience)

Wait, who IS this guy?

  • Developer IV at RealPage in Seattle
  • hacker by nature and trade
  • cut teeth at Classmates.com
  • FLOSS enthusiast, activist, author

Get Crazy with Git

You know version control, but this is...

Distributed Version Control

Distributing a version control system is a pain in the butt. Why bother?

Because awesome.

  • every clone is a complete repository
  • very fast local operations: commit, merge, log, search, bisect
  • also: test changes, undo, destroy, recover

We'll come back to that.

But first, a gentle introduction to Git.

slides 1 through 11

Quiz

In those slides, which operations were local?

Let's Bash a while.

Command line

$ echo Hello, World
        

Saved file

#!/bin/bash
echo Hello, World
        
Bash is a simple, loose, fast shell and programming language.

Basics

Starring... foo.sh!

$ cd /tmp            # change dir to /tmp
$ pwd                # display current dir
$ ls -l              # detailed listing of files in current dir
$ touch foo.sh       # create empty file 'foo.sh'
$ vim foo.sh         # edit foo.sh with Vim text editor
$ file foo.sh        # identify foo.sh based on contents
$ cat foo.sh         # display contents of foo.sh
$ chmod +x foo.sh    # make foo.sh executable
$ chown zed foo.sh   # make user 'zed' the owner of foo.sh
$ ./foo.sh           # execute foo.sh in current dir
$ rm foo.sh          # delete file foo.sh in current dir
$ history            # list recent commands
        

More commands

$ top                       # display Linux tasks
$ yum install emacs         # install emacs operating system
$ at 5pm                    # run a command at 5pm
$ ss -ln                    # display listening ports
$ ifconfig                  # display network interfaces
$ date +%s                  # display seconds since the epoch
$ date -d @398352385        # convert same back to date/time string
$ curl http://icanhazip.com # display public IP address
$ ping google.com           # ping google.com
        

Help!

$ help history      # help for 'history' Bash builtin
$ ls --help | less  # show usage info for 'ls', paged with 'less'
$ man nano          # open the 'nano' manpage
$ git blarf         # illegal, prints helpful message
        

Quiz

What's the best way to get help?

Whatever works. apropos, ask friends, search the web.

Git, inside out

Let's get deeper into Git.

Pipes

$ ls --help | less       # you should know this one by now
$ rpm -qa | grep magick  # list installed packages with 'magick' in their name
        

Redirection

$ echo Hello, World > clobbered-by-stdout.txt
$ echo Hello, World >> appended.txt
$ find /tmp 2> stderr.txt
$ sed -e 's/take/give/' < in.txt > out.txt
        

Job control

$ jobs  # list currently running jobs
$ bg    # resume a job suspended with CTRL-z, in the background
$ fg    # same, in the foreground
        

Enough Bash. More Git please.

Intermediate Git

Bash script: update multiple Git clones

for repo in `\ls`
do
    echo $repo
done | xargs -n1 -I{} git --git-dir={}/.git pull --ff-only
        

But ugh, so slow! Let's pile up blocking operations.

for repo in `\ls`
do
    echo $repo
done | xargs -P8 -n1 -I{} git --git-dir={}/.git pull --ff-only
        

See also