Starting with Git: How can I set the directory to work in?

11,422

Solution 1

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

Solution 2

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
Share:
11,422
guypursey
Author by

guypursey

By day... I'm an experienced manager and communicator with a technical background and a focus on making content creation more efficient and strategic. By night... I like to play around with code and visualisations and I keep (and occasionally update) a blog at guypursey.com. For fun... I write, I read, I eat and socialise, I play board games, and I follow the football.

Updated on June 05, 2022

Comments

  • guypursey
    guypursey almost 2 years

    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...

  • Nevik Rehnel
    Nevik Rehnel about 11 years
    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.
  • Ronnie
    Ronnie about 11 years
    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
  • guypursey
    guypursey about 11 years
    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
    guypursey about 11 years
    Thanks. I'll have a look around for those tutorials.
  • Ronnie
    Ronnie about 11 years
    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
  • guypursey
    guypursey about 11 years
    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).