Git post-update hook cannot pull - windows

I am currently setting up a git schema as described here.
The server in question is running Windows Server 2008 R2, using copSSH and msysGit.
The jist of it is a pair of git repos: one bare repo that is pushed to and then another non-bare repo that contains a live application.
The repo that is pushed to contains a post-update hook that looks as follows:
echo
echo "**** Pushing data to Live Server."
echo
cd /cygdrive/c/Repositories/Live || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
Of note: Live is the non-bare repo which is, as the name implies, live. Live.git is the bare repo which contains the above hook and is pushed to. I was unable to cd to the repo without /cygdrive/, which was uncovered by echoing $pwd in a diagnostic push.
Pull is successfully called in the Live repo, the problem comes in locating the Live.git repo in that update. I get "odd ball" errors that read like:
remote: Pushing data to Live Server.ommand not foundnd not foundle or directory
remote: : not foundpdate-server-infoand not foundand not founddommand not found
hub is defined as a remote repository via the local git shell as both /c/Repositories/Live.git and /cygdrive/c/Repositories/Live.git.
I've replaced "hub" with direct folder paths, even trying things like "../Live.git"
Everything I have tried has ended in a git update failure. All of the attempted paths for Live.git in the update command were attempted via a git bash with the working directory set to the Live repo and worked.
Thank you for any leads or help!
An update:
My schema requires that I pull from the hub repository, it would take an unnecessary amount of room to explain why, but such is the case.
I have done more testing and found more out about my issue:
When I push via SSH to my repository, the prime hub is successfully mounted and the pull command is executed. When said pull command tries to resolve the hub repository it fails (as I detailed above), but it turns out with a series of ls commands in the hook that no folders can be seen. I even ran an ls on /cygdrive/c/ and can only see a folder called usr. I have ensured that the copSSH user has full administrative privileges on the entire file system (only for testing and debugging purposes).
I do not know why my paths have to use the /cygdrive/ path, I do not have cygwin installed besides the cygwin packaged in copSSH. Is this indicative of a problem in my configuration? or is this normal for copSSH + msysGit setups? How is it possible that I can mount the prime repository from the hook, even if ls will not list the repositories folder?

You shouldn't need /cygdrive in paths with msysgit, unless you also have cygwin installed (in which case the combination of msysgit mingw and cygwin might be the source of your problem)

You shouldn't try to run git pull from a repo hook. While some people will say that it works fine, it does not and the behavior can be unpredictable due to various factors.
Instead you should use a method such as this one. http://toroid.org/ams/git-website-howto
That method uses a post-receive hook in a bare repo that calls git checkout to update a directory.

Related

Configure git to be accessed in my network from portable HDD under Windows

I need to have a portable git setup in order to access a git repository in my LAN from a portable HDD, including the computer where the HDD is connected, under Windows. The HDD might be moved from time to time between the computers in my network. I wish to avoid SSH for the moment.
I have installed the portable version of the git, I have made a batch to set the PATH to the requested directories specified in the documentation before running git-bash or git-cmd.
I see it runs, I have made a bare repository, let's say in a path like m:/repo.git. Then, I got stuck as I don't know how to configure the remote in order to do the first push as `git push repo master' from my project path.
I think I should do a 'git remote add repo ' but I fail to set the correct URL or something. I am aware I should change the URL each time the HDD is moved or change the remote.
What are the correct setup steps?
Then, I got stuck as I don't know how to configure the remote in order to do the first push as `git push repo master' from my project path
Let git create that setting for you:
git clone m:/repo.git
cd repo
git --work-tree=..\myproject add .
git commit -m "first commit"
git push
That will import the files of your project in a local repo, which will be able to push back to your bare repo on M:\.
UNC paths are supported too
git.exe clone "d:/dev/SDK" "//comp1/Proj/git/SDK/"

something went wrong when pushing to github with webstorm

As is shown in the image,I'm not sure if the failure is caused by some missing property while setting up webstorm .
The issue is not resolved after a lot of efforts.As a learner,I don't know what to do now.
Meanwhile,something seems wrong as shown in git bash.I've no idea whether the two are directly related.
If you have ever faced these difficulties,could you please give me some idea? Even if it's only a web address.
What I want to do is only pushing my code. Anyone who pushed successfully in any other way will be welcomed to share your method.
If I'm being honest I'm not sure that I completely understand your question, but I will supply some information that will hopefully lead you down the right track.
First in the bash shell, cd (change directory) into your project directory like this:
$ cd /c/foo/bar/yourprojectfolder
In your project top most directory, do you have a .git folder? You may have to show hidden folders in windows to see this directory. If not, you need to initialize a repository with the init command.
$ git init
Initialized empty Git repository in C:/foo/bar/yourprojectfolder/.git/
After running this command, you should see a .git folder inside of the directory you changed to (used cd to get to) earlier.
Next, in order to push, you first need a remote repository to push to. Based on your first picture, I believe that you have successfully created a repository on GitHub. If not however, just log into GitHub and click the 'New Repository' button:
Once a repo has been created, you need to add it as a remote to your local git (in git bash). To do this you need a url (either SSH or HTTPS) to your repo. You can find this url inside of your repository in online GitHub. If you are not certain you have set up SSH, it's best to use the HTTPS url. It should look something like this, but the url itself will be different and specific to your repository:
Copy that url to your clipboard, and then back in git bash run:
$ git remote add origin <PASTE YOUR URL HERE>
You need to make an initial commit of your code to have something to push:
$ git add .
$ git commit -m "Initial commit"
Finally, with the origin repo set up and a commit made, you should be able to push to your origin repo
$ git push -u origin master
You should now be able to view your code on GitHub.

Need help setting up a git server on windows

i'm trying to set up a git server on Windows, but i'm having some issues getting it all to work.
I have locally created a normal repository, and remotely i created a bare repository. On the local repository i added a single text file and committed it, but when I try to push it into the remote repository I always get the following message:
fatal: protocol error: bad line length character: fata
I searched SO and other sources, and most of them suggest it's an issue regarding command echos. I'm using freeSSHd as a SSH solution (remote repository is hosted on a windows server), and I tried to use both the git bash and the windows CMD as a command shell.
I start CMD with /Q to disable echoing and /K to change directory to a directory where repositories are located, so I don't think that would be a problem.
Using the remote desktop, i can clone the repository to a folder next to it, and using the git bash locally i can access the SSH shell and also clone the repository in the same way. But using git clone ssh://<address>:/myRepo.git I always get the above message (The SSH's working folder is the same where the repository is located). Does anyone have any idea what's going on? How can I see what command is triggering the error, and how can I see the full error message?
I also met the same error using freeSSHd as a ssh solution for git server on Windows. I couldn't find a solution for a whole day and gave up. :(
Later I found another powerful ssh server from Bitvise called WinSSHD worked well. It has free version for personal use. I suggest you to switch to it. Though I'd also like to know if there's a fix to the error we both met.
To setup ssh server with WinSSHD is quite simple, and you can add virtual accounts with private/public key access.
The key part is to setup the ssh access for git server. Please follow the steps of the blog here.
It should work well for Windows git client. For Mac, you may meet an error as follows.
grp.sh: No such file or directory
fatal: Could not read from remote repository.
To fix it, you need to create the two files gup.sh and grp.sh in your git bin directory (GIT_PATH/bin or GIT_PATH/libexec/git-core configured in system environment variable PATH) in your git server.
The content of gup.sh:
git-upload-pack.exe $*
The content of grp.sh:
git-receive-pack.exe $*

Cannot clone GIT repository on network drive

Using Windows 7, we have a bare GIT repository set up on a network drive so that multiple users can pull/push from it. I am able to create a new working repo on my local and multiple other networked drives. However, when I try to clone a new working repository on the same network drive (different folder) , it fails.
Using TortoiseGIT, after I right-click and choose "GIT Clone", put in all of the necessary paths to my bare repo (the new working repo is already filled in) and hit ok, I get the following error:
Cloning into 'R:\path\to\new\repo'... done.
error: refs/remotes/origin/master does not point to a valid object!
error: Trying to write ref refs/heads/master with nonexistent object 5d2164db2c61efc7a5598f6ff75ed3fbbb12456e
fatal: Cannot update the ref 'HEAD'.
fatal: The remote end hung up unexpectedly git did not exit cleanly (exit code 128)
and it fails to create the repo. It does however build the new folder & ".git" subfolder structure.
It's not a r/w permissions issue because I can r/w any other files, but just cannot seem to create this newly cloned repo. My co-worker cannot either. Even if I got to another folder on the network drive, I still cannot clone the repo successfully. Surprisingly, if I just copy/paste a repo I created in another location, then manually do a "pull", it works and updates successfully.
Any ideas on what to try next? Obviously I've Googled "exit code 128" and "cannot update the ref 'HEAD'" but cannot find a solution to my issue. It's probably something really simple that we are overlooking, but we're just getting started with GIT and this is really causing us headaches...
UPDATE: I just noticed that when I do a manual pull from GIT to my "copy", it is doing a Fast-Forward. Maybe this provides some additional clues?
From R:/path/to/repo
* branch master -> FETCH_HEAD
Updating 5d2164d..d75bdb7
Fast-forward
Files.py | 3 +++
1 file changed, 3 insertions(+)
Success
Git might be trying to do some smart stuff with hardlinks that fails on the network drive. Try using git clone --no-hardlinks /r/path/to/my/repo or git clone file:///r/path/to/my/repo
Please do this via command line in msysgit
git clone /r/path/to/my/repo /r/some/other/path
Further, I would recommend using git from the command line as it is a tool that was designed to be used from the command line. You will be able to find more help, faster, with any issues that come up for you.

Setting up a Git repository on MacOS X with network drive

The given:
A mac with my work folder set up as Git repository.
A network drive (Seagate FreeAgent GoFlex Home, if that helps).
The task:
Set up the specific folder on my network drive as a place where a backup of my repository can be stored.
What I tried:
Setting up the location through Volumes path as a Remote (via Add Remote in Git GUI) - returned with:
fatal: GIT_WORK_TREE (or --work-tree=<directory>) is not allowed without specifying GIT_DIR (or --git-dir=<directory>
Then, I tried
git --git-dir=Volumes/xxxxxxx/GoFlex_Home/Personal/xxxxxxxx
in the terminal, and though it did not turn up with an error, it does not appear to be of result, as another try to add remote ended with the same error as above.
After that, I started to have doubts if specifying the path to network drive through Volumes and/or trying to add it as remote are the right things to do to solve the task. Maybe there are other ways to accomplish the goal that I am not yet aware of?
I assume you get these errors because nothing exist yet in the network share. A remote must point to an existing repository, so you first have to clone it: in the original repo do:
git clone --bare . /Volumes/xxxxxxx/GoFlex_Home/Personal/xxxxxxxx
This will copy your repository data to the network folder.
Then you can add it as a remote:
git remote add --mirror=push backup /Volumes/xxxxxxx/GoFlex_Home/Personal/xxxxxxxx
You will be able to synchronize both with:
git push backup

Resources