17
HOME  ABOUT US  E-BOOKS  EVENTS  IN PRINT  TOPIC OF THE MONTH  Git For Wind ows Developers – Git Series – Part 1 Posted by Jason Meridth on June 1, 2009 UPDATE: I’ve upda ted the msysgi t installation screens so t hey are more c urrent. Git-1 .7.6 is the la test one as of this up date. The subsequent sc reens show Git- 1.6.3. I assure you that all of the co mmands in the first three parts of this series will work on 1 .6.3. Git For Windo ws Developers – Git Series – Par t 1 Git For Windows Developers – Git Series – Par t 2 Git For Wi ndo ws Developers – Git Series – Par t 3 This post is goi ng to be the first of a few. I plan to co nvey ev ery thin g I’v e learned the past 8 months while using git on a development team. I’m currently working on a Macbook Pro, doi ng Ruby on Rai ls deve lopment with git as the source control. The se posts will be specific to using git on the Windows operating system. This post is going to talk about installi ng msy sgit , creating ssh keys, and creating a local git repository . If y ou a lready have msysgit in stall ed, have created y our ssh keys, and have an existing application you just want to put in a git repository, go here I nstalling ms ysgit On Windows For windo ws, install msysgit (both ssh key generation capabilities and git come with this tool): Download the latest version of msysgit: Ads by Lake Quincy Media 21 DAYS REMAINING UNTIL Los Techies Fiesta 2011 September 30th, 2011 at 6:00 PM St Edwards Professional Education Center St Edwards Professional Education Center - 9420 Research Blv d - Echelon III - Austin, TX 78759 Register Now! Tweet This Event Find this event on Event Registration Online for Los Techies Fiesta 2011  Search Recent Posts Opportunity Git-Achieveme nts on Wi ndow s Gotcha with Gitosis and python- setuptools Gitosis and Gitweb – Part 3 – Gitweb Gitosis and Gitweb – Part 2 – Add Projects and Contribu tors Recent Comments Martyn on Git For Windows Developers – Git Series – Part 1 3KWA on Seeing which Git branch I’m on v ia my console prompt (__git_ps1)

Configurar GIT

Embed Size (px)

Citation preview

Page 1: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 1/17

HOME   ABOUT US   E - B O O K S   EVENTS   IN PRINT   TOPIC OF THE MONTH  

Git For Windows Developers – Git Series – Part 1

Posted by Jason Meridth on June 1, 2009

UPDATE: I’ve updated the msysgit installation screens so they are more current.

Git-1 .7.6 is the latest one as of this update. The subsequent screens show Git-

1.6.3. I assure you that all of the commands in the first three parts of this series

will work on 1.6.3.

Git For Windows Developers – Git Series – Part 1

Git For Windows Developers – Git Series – Part 2

Git For Windows Developers – Git Series – Part 3

This post is going to be the first of a few. I plan to convey everything I’v e learned the

past 8 months while using git on a development team. I’m currently working on a

Macbook Pro, doing Ruby on Rails development with git as the source control. These

posts will be specific to using git on the Windows operating system.

This post is going to talk about installing msysgit, creating ssh keys, and creating a

local git repository .

If you already have msysgit installed, have created your ssh keys, and have anexisting application you just want to put in a git repository, go here

Installing msysgit On Windows

For windows, install msysgit (both ssh key generation capabilities and git come with

this tool):

Download the latest version of msysgit:

Ads by Lake Quincy Media

21DAYS REMAINING UNTIL

Los Techies Fiesta2011

September 30th, 2011 at 6:00 PM

St Edwards ProfessionalEducation Center 

St Edwards Professional

Education Center - 9420Research Blvd - Echelon III -

Austin, TX 78759

Register Now!

Tweet This Event

Find this event on

Event Registration Online for Los Techies

Fiesta 2011

  Search

Recent Posts

Opportunity

Git-Achievements on Windows

Gotcha with Gitosis and python-

setuptools

Gitosis and Gitweb – Part 3 – Gitweb

Gitosis and Gitweb – Part 2 – Add

Projects and Contributors

Recent Comments

Martyn on Git For Windows Developers –

Git Series – Part 1

3KWA on Seeing which Git branch I’m on

via my console prompt (__git_ps1)

Page 2: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 2/17

Going through the setup. Click next past the first window.

 Agree to the GPL terms:

Lewis bradbrook on Git For Windows

Developers – Git Series – Part 3

Colasante Manuel on Git For Windows

Developers – Git Series – Part 1

Jason Meridth on Git For Windows

Developers – Git Series – Part 3

Archives

June 2011

September 2010

May 2010

April 2010

March 2010

February 2010

January 2010

October 2009

September 2009

July 2009

June 2009

May 2009

April 2009

March 2009

February 2009

January 2009

December 2008

November 2008

October 2008

September 2008

August 2008

July 2008

June 2008

April 2008

March 2008

February 2008

January 2008

December 2007

November 2007

October 2007

September 2007

August 2007

July 2007

June 2007

May 2007

April 2007

March 2007

February 2007

January 2007December 2006

Categories

.NET

Agile

agile project management

altnetconf 

apache

apple

ASP.NET

ASP.NET MVC

Automated Build

Ayende

bash

blogging

Blogs

Books

Page 3: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 3/17

Set the installation location (default was fine for me: C:Program FilesGit):

Choose installation options. I don’t like to clutter my desktop, so that one is

unchecked. The last two options give a user two new options on files when right-

clicked in Windows Explorer.  We’ll talk about this later in the post.

C#

castle

charity

community

Community Server 

continous integration

Continuous Integration

CruiseControl.NET

Design Patterns

DotNetNuke

email

Events

firefox

friends

funny

gems

git

gitosis

gitweb

Good Finds

Google Reader 

Hardware

hosting issueshowto

htpasswd

hudson

Instant Messaging

integrityapp

JetBrains

Kernel

keyboard shortcuts

Linux

LosTechies

members

microsoft

migrations

Misc

Mocking

monorail

movies

MSBuild

msdn

MVC

NAnt

nginx

NHibernate

oauth

Open Source

Pair Programming

Personal

pragprog

presentation

principles

Programming

python

rails

rake

ReSharper 

rspec

ruby

san antonioScrum

selenium

selenium remote control

shoulda

slicehost

Page 4: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 4/17

The next screen asks what name the folder that the program will be available from

 when I click Start->Programs, etc:

I use the “Git Bash only” option because it’s the only reason I downloaded msysgit.

The other two options are tightly coupled to the operating system’s current setup.

UPDATE : Via Joshua Flanagan, I was informed that tortoisegit, a UI tool,

suggests that you choose the second option “Run Git from the Windows Command 

 Prompt”. I’ve done both, I just prefer the first option because I don’t use

tortoisegit. Just be aware.

Typical Windows developers won’t interact with other operating systems so choosing

the 3rd option, in regards to non-handling of line-endings is usually best.

SOLID

ssh

Stand-Up

Subversion

TDD

TeamCity

test::unit

testing

textmate

Tools

twitter 

Ubuntu

Uncategorized

Virtual Machine

Visual Studio

vmware

windows

Windsor 

xkcd

XP

Meta

Log in

Entries RSS

Comments RSS

WordPress.org

Page 5: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 5/17

Click next and the installation starts.

Uncheck the readme (who reads those anyway?) and click Finish.

Page 6: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 6/17

Once installed, when I click the Windows button and type git (since I’m using

 Windows 7) I’ll see “Git Bash”, “Git Gui’”, “Uninstall Git”. Click “Git Bash”. You will

see the v ersion at the top of the window. We’re good to go:

I also issue the following commands, “git config –global user.email [email protected]

and “git config –global user.name ‘Jason Meridth’”:

 After I commit code in my new repository, later in the post, we will see why these

are relevant.

Generating SSH Keys

I’ve met a good number of Windows developers who don’t know what SSH is. My 

quick definition of Secure Shell (aka SSH): A secure connection mechanism to other

networked machines that support SSH, usually over port 22. It is pretty much the

default form of remote communication for other platforms. More information if 

 you’re interested.

 History and Retrospective:

I used to use cy gwin + ssh keys for my git stuff on my windows VMs, but have

realized, via advice from a friend, that cygwin will not be the easiest thing to teach to

a typical Windows user. I am in no way assuming that any of our readers are

“typical” windows users, but he’s right. And msysgit needs to become the defacto

 Windows git tool anyway. What better way to help that project succeed than to give

it more users.

I’ll generate the SSH Keys I will use to need to connect to remote repositories. I

issue the following command “ssh-keygen –C ‘[email protected]’ –t rsa” (using your

own email address of course) and then press enter when prompted on file location

and return two more times on both passphrase questions:

Page 7: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 7/17

This will create two files in my /c/Users/jmeridth/.ssh folder. These files are my 

private and public keys (id_rsa and id_rsa.pub). The public key is the one we will be

moving to remote git repository servers in later posts.

 SIDE NOTE : back up these keys to a secure location. If they accidentally getcorrupted, deleted, or changed you will be able to restore them at any time. I ty pe

“secure” because you need to make sure no one gets a hold of your private key. If 

either of those situations occur you can just recreate the keys, but every server that

already has your public key will need the new public key (kind of a headache and

time consuming). I’m speaking from experience on this.

This process will not apply to the remainder of this post, but will for following posts.

Putting My Code Under Source Control With Git

For example’s sake, say we have a folder under C:code. In that folder we’ve created

a folder called “console_app”. Inside this folder is a .NET 3.5 Console application that

 will send “hello world” to the output. Really? Again? Yep.

The easiest thing that works:

Page 8: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 8/17

 

I built the application to ensure the bin and obj folders are created. I’ll explain why 

in a minute. In windows explorer I went to the C:code folder. I right-click the

console_app folder. Notice the two choices of “Git GUI Here” and “Git Bash Here”.

 When chosen they will open the corresponding msysgit tools at that desired location.

Each of these choices shows the two different ways of creating a local git repository 

or converting an existing folder into a git repository. I will show how to use Git Bash

in this post and will use it mainly in this series. (If I get enough response to show Git

GUI, I may do that)

Turning the Console Application Into A Git Repository With Git Bash

Choosing “Git Bash Here” when right-clicking the C:codeconsole_app folder gave me

the following:

Page 9: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 9/17

Pretty much what I’ve already seen, but notice the path “/c/code/console_app”.

For the individuals who aren’t used to a *nix ty pe path structure, that is the same as

C:codeconsole_app.

Finally, Git Commands

In the prompt, type “git init”:

I just turned my folder into a git repository. Really that easy? Yep. Notice the

folder mentioned in the response to the command. The .git folder. For the

subversion users who are reading: Remember how you’d have a .svn folder under

every directory of your repository? Not with git. You only have the one .git folder.

If you delete that, you’re folder is no longer a git repository. Yes, it’s that easy.

 Also, notice the “(master)” on the end of our prompt. That is a nice feature of 

msysgit. It is telling me what git branch I’m are currently in. We will talk more

about that in a future post. I mention it in case anyone notices the new prompt.

Now issue a “git status”:

I will explain this output in a second. I need to create a .gitignore file first. Why?

 You notice that the bin and obj folders and the _ReSharper files are listed? I don’t

 want to include those items in our repository. Why? Those are items that another

developer doesn’t need to successfully get the source and compile. They are specific

to my local environment.

I tried to create a .gitignore file in Windows Explorer and kept getting this error:

Page 10: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 10/17

Page 11: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 11/17

 Alright. Hopefully you are either saying, “yeah, I know, I have to add the files to my 

staging area, and then commit them to my local repository” or “what the heck is

that?”. Maybe even something between like, “I know I have to add them to the

repository….wait, what is a staging area?”.

Here is a picture that illustrates what the basic interactions with a local git repository 

consist of:

(https://reader009.{domain}/reader009/html5/0513/5af867c46facf/5af867d20c6a0.png)

Ignore the “checkout the project” red arrow. Focus on the “stage files” and “commit”

red arrows. Those are the actions you need to take to place/update files in your local

repository . So, currently, all the files for my console_app application are in my 

 working directory . I need to put them into the staging area before committing them

to the local repository.

Common Questions:

Q: Aren’t we in a folder already? How does git know what’s in and what’s not in the

local repository?

 A: The .git folder (we will dive deep on that folder in a future blog post)

Q: What does the staging area give me?

 A: A prepared set of files that you have ready to commit to the local repository.

So I issue the “git add .” command:

Page 12: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 12/17

 And I issue “git status” again:

Now the files are shown as “Changes to be committed”. Git even shows me how to

remove files from the staging area; “git rm –cached <file>”.

I now issue the “git commit –m <message>” command:

The “-m” and subsequent text is the message that is assigned to the commit. I see

the files get added.

I now issue the familiar “git status” command:

“nothing to commit (working directory clean)”. Cool. All of my files are now 

initialized in the git version control system. How do I see what has been committed

to this repository ? Good question. Just issue the “git log” command:

Remember those two git config calls we made earlier? This is where those are

relev ant. They populated the Author information for the commit. What are those

numbers after the commit word? Those are the SHA1 (secure hash algorithm) hash

Page 13: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 13/17

 About Jason Meridth

Continuously learning software developer trying to not let best be the

enemy of better

 View all posts by Jason Meridth→

← Los Techies welcom es Ryan Svihla Git For Windows Developers – Git Series – Part 2 →

Like

Sort by popular now

assigned to this commit. SHA1 hashes are “unique”. Why do I have unique in

quotes? Go read this.

I think that is enough for now and if you have any questions, please leave a

comment. I will update this post upon necessity. In the next few posts I will be

going over the common commands (clone, push, pull, fetch, merge, rebase, remote,

 branch, etc). I will also show you how to interact with Github.com, a remote git

repository via ssh on a LInux box, and Gitosis, a mutli-user and multi-git repository 

management tool. I will be using the Linux operating system for all the remote

servers. The local git commands should be applicable to all platforms once you have

git installed correctly.

I actually have a good portion of the next post already written and will complete it

soon.

This entry was posted in git, windows. Bookmark the permalink. Follow any comments here with the RSS feed

for this post.

Showing 22 comments

Login

 Add New Comment

For Windows OS, Git Extensions is a great UI addon for git, it also installs plugins

for Visual studio 2005/8..

TurtouiseGit is nice as well.

However I think the most important knowledge is what you wrote v ery well

about, the basic bashing and understanding git..

Cheers,

Erik 

Erik 

Still the best tutorial that I could find. Thanks!

Martyn

Martyn

Page 14: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 14/17

 You defintively saved me a lot of time here. thanks a lot, clear and concise. 10/10

!

Colasante Manuel

Incredible post. Immensely useful. T hank you so much.

Michael Delamaza

 You're welcome. Glad it helped.

Jason Meridth

 

Glad the articles helped.

I'm redoing the 3rd and 4th ones soon. And adding a 5th to share some learned

lessons.

Jason Meridth

Unfortunately I had to learn working with git on a windows machine until my 

*nix machine is ready so this was a really helpful article. Thanks for the info.

Tevfik Sertel

Great article thanks - a much better introduction than the ProGit book 

Stephen Dryden …

@Jason

That's fantastic!

Thanks again!

Matthew 

@Adam D.That is an excellent point. I will update the post

Thank you

@Matthew 

Of Course. That is compliments of my fellow LosTechies blogger, Sean Biefeld,

Jason Meridth

Page 15: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 15/17

http://www.lostechies.com/blog... (download link at the bottom of the post)

Nice article. BTW, what color scheme are you using for your Visual Studio? I like

the colors! Mind to share?

Matthew 

I would leave autocrlf to false in your set up UNLESS you ARE planning to do

cross-platform dev. It's not worth the potential problems.

 Adam D.

@Jim

I don't use that tool, but I imagine if you install msysgit and add the git bin folder

to your PATH, you should be able to use git from that console tool just fine.

That is just a guess.

Jason Meridth

 Any advice on how to get git bash working with console2?

Thanks in advance,

Jim

Jim

This GIT thing still feels "forced" on Windows. Think I'll let it mature a little.

Good article though.

mjlefevre

I don't know about Windows 7, but in Windows XP, you could type "edit .file" and

exit and the file would be created. If you have some *nix tools, then you can type

"touch .file"

Only the Windows GUI balks at files that start with periods. Otherwise I don't

have any problems opening or dealing with them once they are created.

Great tutorial though. Thanks!

Ramit Prasad

Gabriel N. Sch enker

Page 16: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 16/17

' Subscribe by email + RSS

Reactions

finally I get onto the Git train too! Have to refresh my Unix skills they are a little

 bit rusty. thanks Jason

Great step by step guide for those doing development in Windows world.

Integrum

@Derick 

I can. It's an easy change to this post and I can add it to future posts.

Jason Meridth

are you going to do "GIT for SVN User" in this series? I 'm still learning the ways

of GIT, and my SVN experience gets in my way a lot. If you aren't going to do

that, though, maybe I will. :)

derick.bailey 

@Erik 

I'd heard about the Git Extensions stuff, but was going to try it out this week.

Thanks for the heads-up. I'm going to focus more on the commands, then the

tools in this series.

@Joshua

I haven't installed tortoisegit in a while and didn't remember that they suggested

that setting on msysGit. I'll update the post accordingly. Thanks for watching out.

Jason Meridth

Thanks for all your git help Jason. Looking forward to the rest of the series!

One thing to note, when installilng msysGit, you recommended the Git Bash Only 

setting for setting up your PATH. However, readers may want to be aware that

the TortoiseGit installation (bottom of http://code.google.com/p/torto...

recommends that you install msysGit with the middle option (run Git from

 Windows Command Prompt). Something to consider if you think you might install

TortoiseGit later. (I haven't, yet)

If you choose the middle option, you still get the git Bash shell - you dont HAVE

to use the Windows Command prompt, as the dialog may imply.

Joshua Flanagan

Page 17: Configurar GIT

8/4/2019 Configurar GIT

http://slidepdf.com/reader/full/configurar-git 17/17

Home

About Us

E-Books

Events

In Print

Topic of the Month

Friends of Pablo

TekPub

St. Edward's Professional Education Center

AgileZen

Virtual Alt.NET

European Virtual Alt.NET

Pragmatic Bookshelf 

ReSharper - Develop with Pleasure!

VisualSVN

NHProf 

NCover

Pablo's Extended Family

CodeBetter

Devlicious

Dimecasts

ElegantCode

LosTechies © 2011

Se Habla Code

Proudly powered by WordPress.

Trackback URL http://lostechies.com

 blog comments powered by DISQUS