Remove common leading spaces When coding in Python, sometimes you want a multiline string within a function, e.g.

def f():
    s = """\
    Line 1
    Line 2
    Line 3"""


(The backslash is to remove a leading newline)

If you try to actually print out s, however, you'll get

    Line 1
    Line 2
    Line 3


That's not what we want at all! There's too much leading whitespace!

The challenge

Given a multiline string consisting of only alphanumeric characters, spaces and newlines, remove all common spaces from the beginning of each line. Each line is guaranteed to have at least one non-space character, and will have no trailing spaces. The output may not have extraneous whitespace, whether it be before or after the entire output or an individual line (with the exception of a single optional trailing newline).

Input may be via STDIN or function argument, and output may be via STDOUT or function return value. You cannot use any builtins which are designed to dedent multiline strings or perform this exact task, e.g. Python's textwrap.dedent.

This is code-golf, so the solution in the fewest bytes wins. Standard loopholes apply.

Test cases

"a"                                  -&gt;   "a"
"   abc"                             -&gt;   "abc"
"   abc\n def\n  ghi"                -&gt;   "  abc\ndef\n ghi"
"    a\n    b\n    c"                -&gt;   "a\nb\nc"
"    a\n    b\n    c\nd"             -&gt;   "    a\n    b\n    c\nd"
"   a   b\n     c     d\n    e f"    -&gt;   "a   b\n  c     d\n e f"


For example, the last test case is

   a   b
     c     d
    e f


and should look like this after stripping leading spaces:

a   b
  c     d
 e f
CJam, 20 14 bytes
qN/_z{S-}#f&gt;N*

Algorithm:

We first split the input on newlines and take a copy (qN/_)
Then the smallest column with non space character is calculated by transposing the newline separated array and then simply looking for the index of the first non-all-space row (z{S-}#)
Then we simply remove that many characters away from each line (f&gt;)
Finally, we join by newline again (N*)

Code Expansion
qN/               e# Read the entire input and split it on newline
   _z             e# Take a copy and transpose rows with columns.
                  e# Now we would have a bunch of all space rows. These rows are the ones
                  e# we want to remove (in form of columns) 
     {  }#        e# Get the index of the first item from the transposed array that returns
                  e# true for this block
      S-          e# From each part, remove spaces. If the part is all-space, it will return
                  e# an empty string, which is false in CJam. We finally will get the index
                  e# of the first non-all-space row (or column)
          f&gt;      e# We take that index and remove that many characters from starting of each
                  e# row of the initial newline separated input
            N*    e# Join the array back using newlines and automatically print the result

Try it online here