Console problems using "Git Bash" - windows

I am using Git Bash to practice Unix commands.
What does the following line mean as soon as I open the console?
palex02#LAPTOP-TO2B6AA MINDF64
Also, when I try to use the ls Desktop command I don't see any files or directories. Also with mkdir (always on the Dsktop) I do not see the folder created (but if I go to the Desktop folder I see that it has been created).
This is the path I use:
~/Desktop
How can I solve this problem?

I've seen that happen when someone is using OneDrive, and they're backing up the desktop.
If that is the cause of your situation, C:\Users\<username>\Desktop exists but its contents were moved. The typical methods of accessing Windows Desktop are now using a different folder called "Desktop" in the OneDrive controlled folder.That would be C:\Users\<username>\OneDrive\Desktop or C:\Users\<username>\OneDrive - <your business name>\Desktop.
In such cases, it's common for the same kind of change to apply to "Documents" and "Pictures" folders, but they're each optional.

Related

Change directory where git bash launches without shortcut or modifying $HOME

The company I work for has a code repository deep within a folder structure, the path of which I have saved in a text file. As I was copying that path from notepad++ and pasting it into a cd command for the hundredth time after launching git bash I began to get the feeling that I was wasting time. Being the good programmer that I am, spending an hour researching how to do something programmatically is obviously preferable to doing something that takes four seconds over and over again. However I have been disappointed to find that all of the readily-available solutions offer one of two recommendations which both feel more like workarounds than an actual config change:
Create a shortcut and modify the "start in" field. This is not acceptable for me because I launch git from the start menu (windows key + type "git"). I don't want to add the extra steps of navigating to the folder where I created the shortcut. Even if I give the shortcut a unique name such as "stupidshortcutname", I am not able to access this shortcut by searching in the windows start menu.
Modify the Windows environment variable HOME. This is not acceptable because I still want cmd to launch in its default location of C:\Users\MyUserNameHere.
With some further research I also found the option of creating a file called .bashrc in my C:\Users\MyUserNameHere directory, and having this run cd <folder I want to go to>, but this still feels pretty hacky for something that I feel should be a configuration somewhere.
Git has its own config files, I would be shocked if none of them allowed for setting the location git will default to launching in. Am I out of luck and/or being too picky?
Create a batch file with name like LaunchGit.bat & write the following command:
start F:\Program" "Files\Git\git-bash.exe --cd=D:\your\deep\workspace\path
Now you can launch it from desktop or place it in your Git home directory (and launch from there)
This may not be the most perfect solution, but it will solve your problem.
And ofCouse this is just an idea and you can change/improve it.
Use git-bash configuration to change the directory, if this is what you want.
In ~/.bash_profile (create it if it does not exist), add
cd /path/to/git/repository
The reason to use ~/.bash_profile instead of ~/.bashrc is because the latter is read and executed when an interactive shell that is not a login shell is started (if exists).

How to change SYMLINK to SYMLINKD in batch script

We're sharing SYMLINKD files on our git project. It almost works, except git modifies our SYMLINKD files to SYMLINK files when pulled on another machine.
To be clear, on the original machine, symlink is created using the command:
mklink /D Annotations ..\..\submodules\Annotations\Assets
On the original machine, the dir cmd displays:
25/04/2018 09:52 <SYMLINKD> Annotations [..\..\submodules\Annotations\Assets]
After cloning, on the receiving machine, we get
27/04/2018 10:52 <SYMLINK> Annotations [..\..\submodules\Annotations\Assets]
As you might guess, a file target type pointing at a a directory [....\submodules\Annotations\Assets] does not work correctly.
To fix this problem we either need to:
Prevent git from modifying our symlink types.
Fix our symlinks with batch script triggered on a githook
We're going we 2, since we do not want to require all users to use a modified version of git.
My limited knowledge of batch scripting is impeding me. So far, I have looked into simply modifying the attrib of the file, using the info here:
How to get attributes of a file using batch file and https://superuser.com/questions/653951/how-to-remove-read-only-attribute-recursively-on-windows-7.
Can anyone suggest what attrib commands I need to modify the symlink?
Alternatively, I realise I can delete and recreate the symlink, but how do I get the target directory for the existing symlink short of using the dir command and parsing the path from the output?
I think it's https://github.com/git-for-windows/git/issues/1646.
To be more clear: your question appears to be a manifestation of the XY problem: the Git instance used to clone/fetch the project appears to incorrectly treat symbolic links to directories—creating symbolic links pointing to files instead. So it appears to be a bug in GfW, so instead of digging it up you've invented a workaround and ask how to make it work.
So, I'd better try help GfW maintainer and whoever reported #1646 to fix the problem. If you need a stop-gap solution, I'd say a proper way would be to go another route and script several calls to git ls-tree to figure out what the directory symlinks are (they'd have a special set of permission bits;
you may start here).
So you would traverse all the tree objects of the HEAD commit, recursively,
figuring out what the symlinks pointing at directories are and then
fixup the matching entries in the work tree by deleting them
and recreating with mklink /D or whatever creates a correct sort of
symlink.
Unfortunately, I'm afraid trying to script this using lame possibilities
of cmd.exe-s scripting facilities would be an exercise in futility.
I'd take some more "real" programming language (PowerShell as an example,
and—since you're probably a Windows shop—even a .NET would be OK).

Windows - hard links to files in a git repository break often

I maintain a private Git repository with all of my config and dotfiles (.bashrc, profile.ps1, .emacs etc.).
On Windows this repository is stored under C:\git\config. Most applications expect the files to be elsewhere, so I added hard links between the repository and the expected locations.
Example
On Linux .emacs is located in ~/git/config/.emacs but emacs expects it to be at ~/.emacs. I run:
$ sudo ln -s ~/git/config/.emacs ~/.emacs
On Windows my .emacs is located in C:\git\config\.emacs, but emacs expects it to be in C:\users\ayrton\.emacs. I run:
PS> cmd /c mklink /H C:\users\ayrton\.emacs C:\git\config\.emacs
Issue
On Linux this seems to work fine: when I update the original file, the contents of the link update and everything stays in sync.
On Windows, the links break after a period of time and the files become out of sync (the file contents are different).
Why do the links break on Windows? Is there an alternative solution?
I've seen this StackOverflow post: Can't Hard Link the gitconfig File
So I’ve finally found a solution that takes the best of both: put the repo in a subdirectory, and instead of symlinks, add a configuration option for “core.worktree” to be your home directory. Now when you’re in your home directory you’re not in a git repo (so the first problem is gone), and you don’t need to deal with fragile symlinks as in the second case. You still have the minor hassle of excluding paths that you don’t want versioned (eg, the “*” in “.git/info/exclude” trick), but that’s not new.
The problem here is that the expected locations are different on Windows vs. Linux. For example, VSCode expects the user settings to be in:
Linux: $HOME/.config/Code/User/settings.json
Windows: %APPDATA%\Code\User\settings.json
Ideally I would like my repository to be platform independent. If take the core.worktree approach (e.g. make core.worktree be / or C:\, then exclude everything except specific files) I would have to maintain two copies of some configuration files when their absolute paths differ across operating systems.
Hardlinks can break if a editor opens/creates the file as a new blank file each time you save. It would not surprise me if Notepad did this because it reads the entire file into memory and has no need for the original file after it has loaded the file.
You can try to create a file symlink instead of hardlink on Windows.

I can't see pasted files in bash for windows

I'm working a programming project from school and decided to give Bash for windows a try. I downloaded the skeleton files for the project and pasted them inside the folder where my bash home folder should be. When I open the terminal and go inside the folder it shows as if there was nothing there even though I'm at the right folder. How can I get the files to be displayed?
EDIT: By now, there is actually a supported way to access these files. You have to use the \\wsl$\Legacy "network" share. For example, you could access your WSL home folder in Windows using \\wsl$\Legacy\home\<username>. Still, you should not directly access the lxss directory.
You are not supposed to touch the LXSS folder ever. The files there are use special attributes which are not understood by normal Windows applications to provide the features of a full Linux file system which NTFS on its own can't provide.
There is one hard-and-fast rule when it comes to Bash on Windows:
DO NOT, under ANY circumstances, create and/or modify Linux files
using Windows apps, tools, scripts, consoles, etc. Creating/changing
Linux files from Windows will likely result in data corruption and/or
damage your Linux environment requiring you to uninstall & reinstall
your distro! Note: Your “Linux files” are any of the files and folders
under %localappdata%\lxss – which is where the Linux filesystem –
distro and your own files – are stored on your drive
If you want to copy a file into a WSL directory which is not under /mnt, then use WSL to copy the file, i.e. use cp /mnt/c/original/folder/of/the/file.txt ~/ for example.
A more advanced alternative is starting a local SSH server in WSL and using Win-SSHFS to mount the WSL root as a drive in Windows. This way, file access will go through WSL.
Its unclear what you're asking in your question. What did you paste? Whole files? Text? Where did you paste it? Did you do the pasting into the bash window? If so was it inside a text file or did you just paste to the prompt? I'm going to assume that you pasted files to the directory that you believe that your bash home opens in i.e ~/. You may not be pasting the files into the correct directory because the default directory for bash on windows is not where you would assume it to be. you should be able to reach your desktop by typing cd /mnt/c/Users/yourUserNameHere/Desktop

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