msysGit Bash cannot escape its home directory? - windows

I start the msysGit Bash using the provided batch file (the one that simulates a Linux environment). Bash starts up in msysGit's home directory (on my flashdrive). I would like to leave this directory to go to my project's directory (also on my flashdrive). So, I enter "$ cd .." This has no effect at all. I type "$ ls" and I'm definitely still in the Git folder. I try "cd ~" which brings me to my user folder, but I can't get to the root directory of my flashdrive. How can I get there with msysGit Bash?
I cannot use git-cmd.bat because the computers at my school deny access to cmd.exe.
Alternative question: How can I run git-cmd without needing administrator permissions?
If there is another distributed-model version control system that works better on portable devices (especially on systems where cmd is restricted and I'm not an administrator), I'll gladly switch to it (if you know of one, please tell).

You should be able to access the root directory of any drive by specify its driver letter:
(for instance)
cd /e

Related

WSL: Using A WSL symlink folder from Windows

I use WSL almost exclusively, and only switch to main windows for browsing and running Windows native programs. I have a git repository located at /mnt/c/myrepo. In order to "install" the code inside /mnt/c/myrepo I need to move it to /mnt/c/otherlocation/renamed. Instead of executing cp -r /mnt/c/myrepo /mnt/c/otherlocation/renamed every time I do a git pull from /mnt/c/myrepo, I would like to symlink /mnt/c/myrepo to /mnt/c/otherlocation/renamed. However when I do this, the program which consumes /mnt/c/otherlocation/renamed isn't able to view the "contents" of renamed as a directory.
I have been all over the WSL github repo and issue tracker trying to find a solution to this issue. I see a lot of exclamations about how symlinks "just work". I have enabled every Windows 10 developer feature I can find, I even followed some reddit thread where someone claimed that purchasing Pengwin and creating a symlink from Pengwin would ensure this compatibility, but I still can't seem to make this work.
The basic usage I need, is allow me to view "renamed" as a directory from windows, or for windows to recognize the symlink as a symlinked directory.
from wsl:
ln -s /mnt/c/myrepo /mnt/c/otherlocation/renamed
from windows:
open file explorer
navigate to c:\otherlocation
open mydir and view the contents as if it were a native directory
How do I do this?
Do the symlink in Windows, in cmd.exe:
mklink /d C:\otherlocation\renamed C:\myrepo
It doesn't make sense creating the symlinks in WSL if both directories are in Windows.
This symlink will work in WSL as well.
The solution to this problem is simply to use the relative path when declaring the link. If you want to link from windows to windows, you should relatively path from the current directory and then you can link anywhere you wish.
From the example, instead of this:
ln -s /mnt/c/myrepo /mnt/c/otherlocation/renamed
Do this:
cd /mnt/c/otherlocation
ln -s ../../myrepo ./renamed

Shell (Bash) - Can I have fully portable .bash_profile / .bashrc / .bash_history files?

Background
I'm a Front End Web Developer that has started moving to PortableApps where I can; at least for the desktop machines I use (Windows) after building a machine and having to re-install Windows multiple times.
It's getting more and more important to use the command line with build automation tools, testing software with a CLI etc.
I have just got portable versions of Git (Bash) and ConEmu working from my Dropbox (but ideally this would work from USB too). This means I have access to a Unix shell on Windows with Git, but the .bash_profile (and .bashrc) I have saved I need to manually copy to the '~' (home) directory for each machine I use.
Question
Is there a way to link my portable console with bash files not located in the home directory of the user on each machine used?
For instance when my console opens and looks for these files, can I ask it to check a different directory without setting any config on each machine? And then get the .bash_history to save here too instead?
You can use symbolic links for .bash_profile and .bashrc:
ln -s /path/to/.bashrc ~/.bashrc
ln -s /path/to/.bash_profile ~/.bash_profile
And inside your .bashrc you can define where your history file is located:
export HISTFILE=/path/to/.bash_history
I don't think there's any way around having .bashrc and .bash_profile in your home directory. Unless you start bash with the --rcfile option:
bash --rcfile /path/to/.bashrc
There is also the system wide file located at /etc/bashrc.

How to make babun/cygwin home directory equal windows home directory?

I just installed babun, a variant of Cygwin. I want the cygwin user home directory to equal my windows home directory.
So, to be clear, I don't want to add the cygwin home to the C:\Users as a new user, I want it to be the same as my current windows home directory.
Now, according to this post, How can I change my Cygwin home folder after installation?, there is a neat way to make the cygwin home directory point to your windows home directory.
You open the file /etc/nsswitch.conf and make sure is has a line db_home: windows. However, after restarting my pc, echo $HOME still says /home/chiel.tenbrinke, which is not what is should be. It should say something like /cygdrive/c/Users/Chiel.tenBrinke.
Why is this not working?
My cygwin version is CYGWIN_NT-6.1-WOW IM-Chiel-2015 1.7.35(0.287/5/3) 2015-03-04 12:07 i686 Cygwin.
Babun has a surprisingly good FAQ. The last entry in the FAQ is How to Use the Windows home directory as Babun's home directory?
For me, it boiled down to:
Create an env var for $HOME = /Users/my_account_name via Win+R sysdm.cpl
Run mkpasswd -l -p "$(cygpath -H)" > /etc/passwd
Run babun install
I'm not sure why Babun doesn't recognize the standard cygwin setting in /etc/nsswitch.conf, and I'm a bit surprised there was no mention of this setting in the Cygwin FAQ. I'm a bit concerned that in spite of what a great collection Babun is, it may fall out of sync with Cygwin quickly if not properly maintained.
I tried an easier way and works perfectly so far.
Just mv your home folder to the location you want, and make a symlink
The first execution after move may prompt errors, run babun install will fix everything.
in /etc/nsswitch.conf
db_home: /cygdrive/c/Users/%H

Git Bash for Windows showing/expecting file paths with forward-slashes, no drive colon

I installed Git Extensions which automatically downloaded and installed Git for Windows, and when I use Git Bash, it shows the file path as /c/whatever/folder rather than C:\whatever\folder, and if I paste in a path from Windows Explorer, it chokes on it because it's expecting forward-slashes and no colon after the drive letter.
When I installed Git for Windows by itself previously, it showed the slashes/colon properly, but was much more limiting and harder to use (especially with copy/paste).
Why is it showing/expecting file paths with slashes and no colon, and how do I fix it?!
http://imgur.com/vMc7fU6
You could also try adding single quotes in the directory path copied from Windows Explorer and pasted in the Terminal prompt (e.g. cd 'D:\Documents\Developer Tools & Docs'). It worked for me. Check out the solution posted in the following link:
Escaping backslash in windows paths passed to unix programs
It's getting tripped up because the \ is an escape character in the Unix/Linux world. If the path you paste is like c:\\somefolder\\anotherfolder, it would be ok, because \\ says "I want a literal \. That said, my git bash understands a single \ as long as the path does not end with it. So cd c:\folder works, but cd c:\folder\ does not work.
BTW what error message is it giving you when it chokes, and can you give an example of a pasted path it chokes on.
This is caused by the Git Bash (Ming) shell, not because of anything git itself is doing.
If you run the mount command inside this shell, you will find that /c/ is the folder where your hard drive is mounted. If you want Git Bash to use a different folder name for your hard disk, you can map your disk to a different folder.
By the way, you shouldn't have to care about this when using git. Repos typically don't (and typically shouldn't) contain files in the root directory of a volume. Even if they did, git references files relative to the repository root. Since any folder that is the root level of a volume will also be the root level of any repo it's in, it will be called / in git, regardless of how the underlying operating system or shell labels it.
For your convenience, here is the output of mount from inside Git Bash on my laptop. You should get similar results. You can see that it indicates that C:\ is mounted on the /c folder.
chris#caerdydd MINGW64 ~
$ mount
C:/Program Files/Git on / type ntfs (binary,noacl,auto)
C:/Program Files/Git/usr/bin on /bin type ntfs (binary,noacl,auto)
C:/Users/chris/AppData/Local/Temp on /tmp type ntfs (binary,noacl,posix=0,usertemp)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)

Why are files created in git bash not visible in Windows explorer?

So I just moved from Ubuntu to Windows (read forced to move, thanks to compatibility issues) and am using Git Bash to pull in my files. I've noticed something extremely strange.
Git Bash is installed in C:\Program Files (x86)\Git\, and when I first run the Git Bash program, the default location is this. Normal right? Right.
But here's the weird part..
When I run the command mkdir srv in the Git Bash command line, I can see it in the Bash window - but I can't see it in Windows Explorer?! What the heck. Same thing happens with files created using vi in the CLI. Invisible in Windows Explorer. (Yes, I have enabled the Show hidden files option in Explorer, so it's not that).
Here are some snapshots (no, I'm not blind - nor am I insane). Help?
You might not be able to see the folder because of missing privileges. Try running your explorer as Administrator and look again.
The proposed solutions above didn't help me. However, I copied the hidden directories to another place via git bash. Then I copied them once again via windows explorer to the original place. Now they've become visible. I created those invisible folders via git bash with git clone command before.
I had similar issue, but with file attributes, not with missing privileges.
In cmd under C:\Program Files (x86)\Git\ run command attrib
attrib *
You will know if srv folder has System or Hidden file attribute.
If you would like to view it in cmd then use dir /a:s

Resources