I can do ssh windowsmachine from Linux to access a Windows machine, and from there I can git init --bare foo.git, telling me Initialized empty Git repository in C:/Users/unhammer/foo.git/
but how do I clone that from the unix side?
$ git clone ssh://windowsmachine:foo.git
Cloning into 'foo'...
fatal: No path specified. See 'man git-pull' for valid url syntax
$ git clone ssh://windowsmachine:C:\\Users\\unhammer\\foo.git
Cloning into '\Users\unhammer\foo'...
fatal: No path specified. See 'man git-pull' for valid url syntax
$ git clone ssh://windowsmachine:/foo.git
Cloning into 'foo'...
fatal: ''/foo.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
and similar messages for /C:/Users/unhammer/foo.git and
/C/Users/unhammer/foo.git and /Users/unhammer/foo.git.
Note the double single-quotes:
fatal: ''/Users/unhammer/foo.git'' does not appear to be a git repository
This doesn't happen when I try to git clone linuxmachine:/some/path/that/does/not/exist.git, then git uses single single-quotes. (Maybe that's the issue, git-for-windows or something applying extra quotes?)
The easiest solution is to change the default Windows OpenSSH shell to bash. You can do this easily from powershell on the Windows machine:
powershell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\bin\bash.exe" -PropertyType String -Force
You may have to restart OpenSSH on the Windows machine and/or kill existing ssh connections from the client before it takes effect. Now you can clone without any extra -u option:
git clone ssh://windowsmachine/c/Users/unhammer/foo.git
(and if you previously specified uploadpack/receivepack, remove them from .git/config)
Following #phd's link to https://stackoverflow.com/a/8050564/7976758 I found a reference to https://stackoverflow.com/a/2323826/69663 with a workaround to the quoting issue. Here's what I did:
On Windows, open Git Bash and, in my homedir:
echo 'git-receive-pack "$#"' >grp.sh
echo 'git-upload-pack "$#"' >gup.sh
On Linux, clone specifying upload-pack:
git clone -u '"C:/Program Files/Git/bin/bash.exe" gup.sh' ssh://windowsmachine/c/Users/unhammer/foo.git
cd foo
git config remote.origin.uploadpack '"C:\Program Files\Git\bin\bash.exe" gup.sh'
git config remote.origin.receivepack '"C:\Program Files\Git\bin\bash.exe" grp.sh'
So the repo path is the one that Git Bash shows (/c/Users/$username/$repo), no colon anywhere.
https://github.com/PowerShell/Win32-OpenSSH/issues/1082 seems related.
Related
I want to create a git alias git dir, which when used should open the git installation folder via Windows Explorer, how to implement such an alias?
If using Git Bash, try:
git config --global alias.dir '!start "" "$(git --exec-path)"'
Reference: Can I use the "start" command with spaces in the path?
Starting an alias with ! treats it as a command.
I don't have a windows machine at hand, but for Linux:
git config --global alias.open '!git --exec-path | xargs xdg-open'
Works as described.
So the command you're looking for will probably look something like:
git config --global alias.open "!git --exec-path | 'sed s~/~\\~g' | xargs explorer"
I need to run a script which notifies my CI server after I push. Therefore I need to alias "git push" into "git push; powershell script.ps1". Here is what I am trying:
$ alias git push='git push; powershell script.ps1'
bash: alias: git: not found
Alternatively, denoting whitespace characters returns this:
$ alias git\ push='git push; powershell script.ps1'
bash: alias: `git push': invalid alias name
$ alias "git push"='git push; powershell script.ps1'
bash: alias: `git push': invalid alias name
How can I alias my script to run every time I push?
This worked:
git config --global alias.push "push; powershell ./script.ps1"
The command runs, but using "git push" still doesn't run my script.
Yes, I know that I can use webhooks for this, but it is imperative that the CI server remains fully local. Yes, I know that I can use NGROK for that, but my company does not allow it.
Git doesn't allow alias names to override proper command names. Use another label for your alias.
And if the alias content mixes a git command and shell commands, you'll have to prepend a ! to tell git to pass the command for the shell to interpret.
Try
git config --global alias.p '!git push; powershell ./script.ps1'
# then to invoke it, just
git p
Another slight improvement would be to use && instead of ; to chain your commands, in case the push fails. It would then stop from executing the unnecessary following.
git config --global alias.p '!git push && powershell ./script.ps1'
I executed this command "C:\Program Files (x86)\Git\bin\git.exe" clone ssh://<user>#<org>:<path to repo> in Git bash terminal and in normal command prompt.
When executed in Git Bash terminal, the clone works fine, but while running it in command prompt, it gives following error.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I need to run git clone through windows batch script, that's why
i need to make it run through command line. How to do that work ?
Note :-
1. Add public key to remote(gerrit) that was generated using ssh-keygen.
Your SSH identity is not found while running from command line. Make sure that %HOME%\.ssh directory contains your keys.
I do same task often of committing and pushing changes to remote branch. Being lazy sometimes, I needed to put set of git commands to automatically perform these steps:
cd D:\wamp\www\projectName
git checkout dev
git add .
git commit -am "made changes"
git push
pause
I also tried:
cd D:\wamp\www\projectName
call git checkout dev
call git add .
call git commit -am "made changes"
call git push
pause
and
cd D:\wamp\www\projectName
git.exe checkout dev
git.exe add .
git.exe commit -am "made changes"
git.exe push
pause
Everything works excpet for the final push command. Here is output:
D:\wamp\www\givingcircle>git checkout dev
Already on 'dev'
Your branch is ahead of 'origin/dev' by 1 commit.
D:\wamp\www\givingcircle>git add .
D:\wamp\www\givingcircle>git commit -am "made changes"
# On branch dev
# Your branch is ahead of 'origin/dev' by 1 commit.
#
nothing to commit, working directory clean
D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
D:\wamp\www\givingcircle>pause
Press any key to continue . . .
As you can see, for push, I am getting:
D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
When I run above commands via git shell itself, everything works fine. I have also added git to Windows Path env variables.
Does anyone have an idea of why it works on git shell and not on batch command ? (even though other commands work but not push)
For me, by default, Windows executes .sh files correctly using Git Bash. So I would write your script as a regular bash shell script:
#!/bin/sh
cd /d/wamp/www/projectName
git checkout dev
git add .
git commit -am "made changes"
git push
echo Press Enter...
read
I had a similar need, to be able to move code from BBCloud to our development test servers, for stage 1 testing.
To do this, I created a Windows scheduled task:
Under "Actions", I added "C:\Program Files\Git\bin\bash.exe" in Program/script field (the quotes were required).
In the "Add arguments" field, I entered c:\path\to\bash script\pull.sh.
I then completed the Task Scheduler wizard (run frequency, time, etc.).
I then created a bash script, using Nano in Git Bash for Windows containing:
#!/bin/bash
cd /c/path/to/bash script
git pull
I would prefer a push to the repository automatically pushing down to the test server, but Pipes, Webhooks, and DeployHQ don't seem to be a solution for our environment.
Try this one !!
cd c://TESTS/path
set HOME=%USERPROFILE%
GIT COMMAND GOES HERE
pause
I'm running cap deploy to deploy a site to a server. It deploys just fine, except for this last part:
export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git submodule -q update --init $GIT_RECURSIVE && (echo b8ce153ac56e3e79eda1e053b922ac48e775321a > /var/www/alkdfjf/releases/20130822204731/REVISION)
If I didn't have git, I have git installed, as it clones just fine. But at this step, I receive an error stating:
bash: "git: No such file or directory.
I think the .git folder those files are in is usually hidden and needs higher privileges. Are you sure you don't need or that you are sudo or whatever the equivalent is on Macs?
Use the full path to git in your command, i.e. /usr/local/bin/git or what ever it is on your system.