Starting with Git: How can I set the directory to work in?
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:
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 howdir
looks by default in cmd.exe), you can usels -la
(the two options mean "long format" and "show all entries"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 becd ..
;cd..
won't work); more examples:cd localfolder/subfolder
,cd /c/absolute/path/example
mkdir
(there is by default nomd
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
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, 2022Comments
-
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 likedir
to list everything in a folder, andcd
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 thegit 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...
- DOS/Windows to UNIX/BASH command line conversion tables
- A-Z index of BASH commands, not all of which work with Git (e.g.,
dir
!) - git - a simple guide -- very useful but also illustrative of the problem I experienced as a beginner, as witness the comment 'perform a git init? With what, where?'
- [added 20130319] Getting Around in Linux (a useful intro to basic Bash commands)
- [added 20130319] LifeHacker's Command Line Primer
-
Nevik Rehnel about 11 yearsYes, 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 about 11 yearsOh 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 about 11 yearsThanks @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 about 11 yearsThanks. I'll have a look around for those tutorials.
-
Ronnie about 11 yearsThanks @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 about 11 yearsFollowing 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).