3

Very basic beginner question on Git, from someone with very little command line experience.

  • I have Git Bash open.
  • I have been following this very useful guide, which I have understood up to a point.
  • I want to use git init command to start working in a folder.

When opening Git Bash I'm shown my username and computer name (in the form username@computername) and given a $ prompt. In Windows' cmd.exe I can use commands like dir to list everything in a folder, and cd to change to a particular folder, but unless I've missed something these commands aren't available to Git Bash.

QUESTION: The guide says 'if you’re starting to track an existing project in Git, you need to go to the project’s directory and type $ git init'. How can I list and navigate to folders where I might want to use the git init command in Git Bash?

...

...

...following the answers below...

RESOURCES FOR OTHERS: Since getting the answers below (which helped clear up my beginner's confusion about the Bash scripting language and Git Bash), I've found the following resources which might be useful to others struggling to get started...

9
  • @Mat I looked up Bash beforehand to see if there was more general advice but I wasn't sure how much of it would be applicable to Git. That was naive I suppose. As I said, I have very little command line experience and the question is possibly embarrassing...
    – guypursey
    Commented Mar 10, 2013 at 14:26
  • "Git Bash" is just the name of a package that contains a Windows port of Bash, and a Windows port of Git. You have a (mostly) full Bash environment. Plus Git. Git is just a set of executables you run from a command line.
    – Mat
    Commented Mar 10, 2013 at 14:27
  • Thanks @Mat. I see there is a good answer addressing that below. Looks like I have some reading to do.
    – guypursey
    Commented Mar 10, 2013 at 14:30
  • Just as an afterthought, it's a shame the exasperated-sounding comment above got 3 upvotes and the genuinely helpful answer below only got 2 (one of which was mine).
    – guypursey
    Commented Mar 10, 2013 at 14:42
  • 1
    If you know the Windows command line, and you don't know Unix/Linux, then I'd recommend just using Git from the Windows command line. It mostly works the same way. The only major caveats are that paths you pass to Git need to use forward-slashes, and HEAD^ doesn't work in DOS (but HEAD~ does). If you're installing msysgit, use the "Run Git from the Windows Command Prompt" option.
    – Ryan Lundy
    Commented Mar 10, 2013 at 15:45

2 Answers 2

5

You might want to look at a beginner's tutorial for Bash, which will teach you the basics about navigating and file manipulation you will need.

Alternatively or additionally, you can look for tutorials on how to use Git in cmd.exe or in PowerShell (it works in both, but has some quirks and takes some additional setup).

For now, the commands you need are:

  1. ls to list a directory's contents. ls uses a short multi-column layout by default, if you want to know more about files (similar to how dir looks by default in cmd.exe), you can use ls -la (the two options mean "long format" and "show all entries"
  2. cd (equivalent: chdir) to change the directory; it takes one argument, which is the path of the folder you want to change into; it can be absolute or relative, and must exist; difference to cmd.exe's cd: if you want to go up one level, don't forget the space (must be cd ..; cd.. won't work); more examples: cd localfolder/subfolder, cd /c/absolute/path/example
  3. mkdir (there is by default no md alias for this, though you can define it if you want) to make a directory; works like in cmd.exe: mkdir new_folder_name
2
  • Thanks. I'll have a look around for those tutorials.
    – guypursey
    Commented Mar 10, 2013 at 14:36
  • 1
    Following the pointers here I added some resource links to my question (though I still consider this to be the correct answer to my specific, original question).
    – guypursey
    Commented Mar 10, 2013 at 15:40
4

use ls instead dir, cwd, chdir or cd for changing directory...

Like

$ cd /I/want/to/go/here
$ ls
.
..
File1
File2
............
............
$ mkdir Folder1
$ cd Folder1
$ git init
4
  • Yes, it is "Git Bash" in this case, which is installed by MSYSGit on Windows and brings some configuration customized for the use of Git. Commented Mar 10, 2013 at 14:27
  • Oh I don't have enough experience on Windows systems.. From the day I use computers I have linux installed and perhaps missed the point since when I use Git, nothing special is required. I can directly type in $ git init etc. So, Perhaps I am wrong. Thanx for it
    – Ronnie
    Commented Mar 10, 2013 at 14:34
  • Thanks @Ronnie. Though I marked the other answer as correct because it was fuller, I appreciate you got in there first and I had actually tested your commands first. So +1 for that from me. Welcome to Stack Overflow!
    – guypursey
    Commented Mar 10, 2013 at 14:35
  • Thanks @guypursey. Yes, the other answer was fuller. I too have +1ed it. And also, Itz my (bad) habbit to describe less, and give more examples.. I simply believe that, I learn more from examples than descriptions... U're the first one who +1ed me....... it helped
    – Ronnie
    Commented Mar 10, 2013 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.