How to manage files of link source by git? - linux

Want
I wanna manage nvim config by git.
Problem
Link is break by git checkout . command. Expect behavior is overwrite my nvim config with remote repository source. But actual behavior is overwrite link with remote repository source.
Code
I was tried as bellow code.
# clone
cd ~/Documents/GitHub/
git clone https://github.com/ShortArrow/my-nvim-config
cd my-nvim-config
# delete "./nvim" for making link
rm -r ./nvim
# making link
ln -s ~/.config/nvim/ ./nvim
# if you need, "cp ~/.config/nvim/ ~/.config/nvim-backup"
# I wanna rewrite nvim config by git with this command
git checkout .
Already Tried
try1
sudo git config --system --unset core.symlinks
git config --local core.symlinks false
try2
$> sudo ln -d ~/.config/nvim/ ./nvim
ln: failed to create hard link './nvim' => '/home/who/.config/nvim/': Operation not permitted
On Windows
This github repository is working good with Junction link on Windows.

A softlink is just a file with the target path in it (and a permission flag telling the OS to treat it as a link), and Git is treating it as such.
Instead of changing what is in the repository by changing the repository file into a link to the config file, link the other way: make the config file link into the repository.

Related

Cannot create git repo in davfs2 mount

On Linux Debian 9, I'm trying to create a git (ver. 1:2.11.0-3+deb9u2) repository within a Cryptomator (ver. 1.3.2) WebDAV server mounted via davfs2 (ver. 1.5.4-2+b1). After running git init to create the git repo, I get the following error:
error: could not lock config file /home/nonrootuser/Documents/mounteddrive/gitrepo/.git/config: Permission denied
fatal: could not set 'core.repositoryformatversion' to '0'
Same issue persists with nonrootuser and root.
To reproduce:
git and davfs2 are available via Debian repositories. Cryptomator 1.3.2 is available here:
https://github.com/cryptomator/cryptomator/releases/tag/1.3.2
Create a blank folder for the davfs2 mount:
cd /home/nonrootuser/Documents/
mkdir mounteddrive
Create a vault with Cryptomator and unlock it. For the unlocked vault, click the dropdown arrow and select Copy WebDAV URL. Paste the WebDAV URL into the following command and run in terminal:
mount -t davfs -o gid=nonrootuser,uid=nonrootuser pasteWebDAVURLhere /home/nonrootuser/Documents/mounteddrive
(hit enter twice, leaving Username and Password blank)
The Cryptomator vault is now mounted to the folder mounteddrive.
In terminal, run the following:
cd /home/nonrootuser/Documents/mounteddrive
mkdir gitrepo
cd gitrepo
git init
Here you should see the error described above. However, a .git folder is still created within the gitrepo directory. When running ls -la in gitrepo, it seems to indicate I have the appropriate permissions, and I can create arbitrary files within the .git folder; what I cannot create is an empty file called config.lock, which I believe is what git is trying to do.
This may be completely off-base, but I've tried turning locks on and off (see use_locks) in the davfs2.conf file that can be edited by running the following as root:
mousepad /etc/davfs2/davfs2.conf
To try to obtain the appropriate permissions to create config.lock, I've tried changing my git user.name to "root" and "nonrootuser":
git config --system user.name "root"
git config --global user.name "root"
and
git config --system user.name "nonrootuser"
git config --global user.name "nonrootuser"
I've also tried running the following in the gitrepo folder as both root and nonrootuser:
chmod -R 777 .git
However, git init still returns an error.
git is working fine on my system outside of cryptomator/davfs2 mounts. I've not used davfs2 previously without cryptomator, so I don't know if the former, latter, or both are the problem.
Any ideas are appreciated.

How can I verify git clone is working correctly?

I'm following the documentation provided here by git to setup a bare git repository in a folder called root.
I started in the root directory where I ran
git init
git -A *
git commit -m "test"
I then ran git status and all appears good.
Next I ran the line from the documentation at a directory one level above the repo I created above.
git clone --bare root root.git
This created root.git but I cannot see any evidence that anything was cloned I just see a set of files and directories when I cd root.git.
I don't know how to verify it was actually cloned, and if it was why can't I see the original files?
When you do --bare --- you are telling git to clone just the git portion -
This is the option you use when you want to have a remote repository that does not include a workspace.
If you want to verify that it actually cloned your changes, you'll want to clone it again in a different directory - without the --bare flag
I would recommend using the full path to do this:
cd /path/to/some/workspace
git clone /path/to/your/root.git successful-git-clone #that last bit is optional
This will put the workspace contents of root.git into a folder named successful-git-clone/ - without that last bit, it will default to root/ -
Even if you are in a bare repository, some git commands works and you could do a git branch to see if you have all your branches or git log to look at your commits...

Git ignore and changing the history (on Windows)

I've already read several posts about this here (like Git ignore & changing the past, How to remove files that are listed in the .gitignore but still on the repository?, and Applying .gitignore to committed files), but they have several problems:
Commands that only work on Linux.
Incomplete commands (like the first post I've linked to).
Only for one file.
I have pretty much no experience with Git so I was hoping for some help here.
What I'm basically trying to do is rescue one of my projects history. It's currently Hg and I converted it to Git with Hg-Git (all very easy) and it includes the history (great!). However, I also added a .gitignore file and added several new files & folders that I want completely gone from the history (like the bin and obj folders, but also files from ReSharper). So I'm looking for a way to apply the .gitignore file to all of my history. The commands should work on Windows as I have no intention of installing Linux for this.
No need to add the .gitignore in the history (there is no added value to do it), just add it for your future commits.
For the remove of files and directories in your history, use bfg-repo-cleaner which is fast, easy and works very well on Windows (done in scala).
It will do the job for you!
This is working for me:
Install hg-git.
cd HgFolder
hg bookmark -r default master
mkdir ../GitFolder
cd ../GitFolder
git init --bare
cd ../HgFolder
hg push ../GitFolder
Move all files from GitFolder to a '.git' folder (in this GitFolder) and set this folder to hidden (not the subfolders and files).
cd ../GitFolder
git init
git remote add origin https://url.git
Copy all current content (including .gitignore) to GitFolder.
git add .
git commit -m "Added existing content and .gitignore".
git filter-branch --index-filter "git rm --cache d -r --ignore-unmatch 'LINES' 'FROM' 'GITIGNORE'" --prune-empty --tag-name-filter cat -- --all
git rm -r --cached .
git add .
git gc --prune=now --aggressive
git push origin master --force
There is probably an easier way to do this and it might not be perfect but this had the result I wanted.

can git be run with less file permissions than the files it tracks?

here is the situation: i want to use git to track a directory of preference files that are owned by root.
it would be nice if git commands that don't modify the files (like git status and git diff) can be run as the user (without sudo).
through the following steps, i've created a repo that seems to function in a reasonable manner:
sudo mkdir .git
sudo chmod <user>:<group> .git
git init
git add .
git commit -m "initial commit"
i can run git status and git diff as the user. git checkout ... and git reset ... fail as the user, but seem to run fine when prefixed with sudo.
this seems perfect: no sudo needed to get into the repo and take a look at what's gone on, but to change the tracked files requires an extra level of effort, as it should for system files.
the question is: will this cause me any problems with how git is reading and writing files inside the .git directory? will any commands i need sudo to run end up creating things inside .git with root permission that will then cause problems trying to run commands that don't modify the tracked files as the user?
thanks and advance for any answers.

Out of the box support for deployment in wintersmith

Is there an automated way to easily host a static site made with wintersmith on Github Pages or Heroku?
I have tried writing a gruntfile, shell scripts and a couple of suggestions that were mentioned in this issue but all of them were quite difficult to setup.
I am basically looking for something as simple as this -
wintersmith new myblog
npm install
wintersmith deploy
PS:
Can someone put a new wintersmith tag to this question?
Here are some general guidelines based on my set up for github pages. (more info on github pages)
I have two folders. One for wintersmith, and one which is a git repository folder.
./myblog/ (wintersmith)
./personalblog/ (git repo)
On configuring your git repo, create ./personalblog/ via:
mkdir personalblog; cd personalblog
git init
git branch -m master gh-pages (this is important! see: https://help.github.com/articles/user-organization-and-project-pages#project-pages)
Create a repository of the same name on github. Then set the origin of the local repo. See here for more info.
Within ./myblog I'd have a bash script (build.sh) with the following:
#!/bin/sh
# ./myblog/build.sh
# other build commands such as javascript or css minifiers
rm -r ./build/
wintersmith build
Then, I check and verify the wintersmith build. I verify using nodejs http-server. I'd have another bash script file for deployment:
#!/bin/sh
# ./myblog/deploy.sh
# rsync to efficiently sync ./myblog/build to ./personalblog/
# ignore deleteing .git folder and other stuff
rsync -rtvu --delete -f"- .git/" -f"- CNAME" -f"- .gitignore" -f"- README.md" ./build/ ../personalblog/
# change dir
cd ../personalblog/
# sync to github
git add -A
git commit -am "Commit on $(date)"
git push origin gh-pages
Hopefully these guidelines are helpful for you.

Resources