A Git Primer – For this primer, we'll be using – Why does this matter?



A Git Primer – For this primer, we'll be using – Why does this matter?

0 0


talks

An Introduction Talk for Git

On Github rogeruiz / talks

A Git Primer

by Roger Steve Ruiz

We'll be going over:

How to configure Git on your machine

A base Git workflow that will get you started:

  • cloning
  • pulling
  • statusing
  • adding
  • committing
  • pulling, again
  • pushing

For this primer, we'll be using

A Basic Terminal Window

And...

Your hands

finally...

Your Keyboard

Configuring Git

A pretty decent .gitconfig file

So, how do I set up something like this?

$ git config
					
						
usage: git config [options]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    -f, --file <file>     use given config file

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 adds a new variable: name value
    --unset               removes a variable: name [value-regex]
    --unset-all           removes all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            opens an editor
    --get-color <slot>    find the color configured: [default]
    --get-colorbool <slot>
                          find the color setting: [stdout-is-tty]

Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)

Other
    -z, --null            terminate values with NUL byte
    --includes            respect include directives on lookup
						
					

Wow, that Looks pretty rough.

Making Git aware of your name

$ git config --global user.
user.name       -- full name used for commits
					

Making Git aware of your email

$ git config --global user.
user.email       -- email address used for commits
					

Making Git aware of your ability to discern color

$ git config --global user.
color.ui       -- when to color if output is capable; most generic option, overriding by more specific ones
					

Why does this matter?

Your name and email address will be tied to each commit you do in Git

							
	$ git log
							
						
	commit d49ac57e4edf85d30b2c679437725edd05ffb2bf
	Author: Roger Steve Ruiz <roger.ruiz@rokkan.com>
	Date:   Wed Sep 26 19:50:18 2012 -0400

	    Adding the thing that I removed

	commit a1e73b78ef6ec05599794e7cfd0b91bd7a10eb88
	Author: Roger Steve Ruiz <roger.ruiz@rokkan.com>
	Date:   Fri Sep 21 09:27:31 2012 -0400

	    Removing that thing that I added

	commit edb20515291544f847eab2691d554b5d19662c28
	Author: Roger Steve Ruiz <roger.ruiz@rokkan.com>
	Date:   Fri Sep 21 09:18:55 2012 -0400

	    Gangnam Style
						

Why else does this matter?

Now with color.ui being active, you'll have colors!

Okay. Now that I'm all set up, now what?

Let's get into a workflow.

Cloning

						
$ git clone git@lamp.rokkan.com:Client-Project.git /a/random/folder/Client-Project
						
					

Seriously, wherever you want it.

I mean it.

Anywhere you want.

Just specify the path and the folder name.

Pulling

						
$ git pull origin master
						
					

Now modify some files

(i.e. Work)

Statusing

						
$ git status
						
					

Adding

						
$ git add .
						
					

Committing

						
$ git commit -m "I have added a bunch of files to commit & I am committing all of them."
						
					

Pulling, again.

						
$ git pull origin master
						
					

Pushing

						
$ git push origin master
						
					

And like it says on your shampoo,

REPEAT

  • pulling
  • working
  • statusing
  • adding
  • statusing, again
  • committing
  • pulling, again
  • pushing
  • repeat

Keep in mind, this kind of workflow mimics an SVN workflow pretty closely. Because you're pushing so often, you'll have your work on the remote repository as soon as you're done committing it. There are other ways to work when it comes to Git and keep in mind that over time you'll develop you're own Git workflow.

And That's All Folks

Thank You

BY Roger Steve Ruiz

Rokkan 2012