Now I know there are several questions like this on overflow but several of these answers have failed miserably for me. I am using Cygwin, if it is relevant. I ran
svn export https://github.com/Wikia/app/tree/dev/extensions/wikia/AdminDashboard
to receive the result:
svn: E170000: URL 'http://github.com/Wikia/app/tree/dev/extensions/wikia/AdminDashboard' doesn't exist
I also ran
curl -L http://github.com/Wikia/app/tree/dev/extensions/wikia/AdminDashboard > project.tar.gz
to receive a .tar.gz file that 7-Zip fails to read the file giving the error:
Two remarks:
A GitHub repo would not work with svn command
the url does not exist.
A GitHub repo is best clone in its entirety, but you can do a sparse checkout as in this gist or this article:
New repository
mkdir <repo> && cd <repo>
git init
git remote add –f <name> <url>
git config core.sparsecheckout true
echo some/dir/ >> .git/info/sparse-checkout
echo another/sub/tree >> .git/info/sparse-checkout
git pull <remote> <branch>
Existing repository
git config core.sparsecheckout true
echo some/dir/ >> .git/info/sparse-checkout
echo another/sub/tree >> .git/info/sparse-checkout
git read-tree -mu HEAD
If you later decide to change which directories you would like checked out,
simply edit the sparse-checkout file and run git read-tree again as above.
Related
First off, I am not using command line git at all. I am only using SourceTree's gui interface. I would prefer to solve my problem this way; if possible.
Somehow, my submodule has become corrupted. Attempting to fetch or pull gives me the following error:
I haven't found any answers for this particular problem. I am fortunate in that my remote master is ok, 100% up to date, and I have no local changes. So, I think the easiest way will be to just fully reset my local submodule.
However, I can't figure out how to do so.
I considered trying to remove my submodule and then re add it. However, I have had problems with that in the past, and so am gun shy.
I found handfuls of posts about resetting to a specific commit. However, the SourceTree gui is failing to populate my history because of this error.
Any help would be appreciated
Thank you
You can try this
Right click at your conflicted branch at BRANCHES and delete it.
Double click at your remote branch at REMOTES to re-download and switch to that branch.
Easy, good luck.
I finally did get this fixed. I had to give up and use the command line.
I found this page (git fatal: failed to read object xxx: Invalid argument). That pointed me to using the "git fsck --full" command.
That pointed me to a very specific folder in the .git hierarchy that was corrupted.
I needed to delete this folder, but doing so wasn't easy. Windows would let me delete it. Not in safe mode. Not with cmd del or rmdir. I had to run a scan disk from windows on my entire drive. That ended up detecting the folder and removing it.
Finally, from there, I was able to fetch and pull master again.
From all the solutions I was able to find to perform an actually hard reset with proper cleanup and reinitialization of submodules nothing worked. So I ended up creating a custom script. Following will perform a full cleanup of your submodules and will recreate them as if you were cloning the parent repo.
#!/bin/bash
echo "Backing up current .gitmodules"
cp -f .gitmodules .gitmodules.bkp
has_submodules=$(echo "$(git submodule)")
if [ "$has_submodules" != "" ]; then
git submodule deinit --force .
rm -rf .git/modules
git submodule | cut -c43- | while read -r line; do (git rm -f "$line"); done
fi
cp -f .gitmodules.bkp .gitmodules
PARAMS=("path" "url" "branch")
CHUNKS=${#PARAMS[#]}
PARAMS_STR=$(IFS='|'; echo "${PARAMS[*]}")
readarray -t SUBMODULES_INFO_ARRAY < <(git config -f .gitmodules --get-regexp '^submodule\..*\.('"$PARAMS_STR"')$')
SUBMODULES_INFO_ARRAY_STR=$(IFS='|'; echo "${SUBMODULES_INFO_ARRAY[*]}")
function process_submodules_parsed_array()
{
name=${SUBMODULES_PARSED_ARRAY[0]}
path=${SUBMODULES_PARSED_ARRAY[1]}
repo_url=${SUBMODULES_PARSED_ARRAY[2]}
branch=${SUBMODULES_PARSED_ARRAY[3]}
echo "Running: git submodule add --force -b "$branch" --depth 1 --name "$name" -- "$repo_url" "$path""
git submodule add --force -b "$branch" --depth 1 --name "$name" -- "$repo_url" "$path"
}
echo "Parsing current .gitmodules"
for((chunk=0; chunk<${#SUBMODULES_INFO_ARRAY[#]}; chunk+=CHUNKS))
do
section_name="$(sed -nE 's/^submodule\.(.*?)\.'${PARAMS[0]}'\s(.*?)$/\1/p' <<< "${SUBMODULES_INFO_ARRAY[chunk]}")"
SUBMODULES_PARSED_ARRAY=("$section_name")
for ((param_i=0; param_i<CHUNKS; param_i+=1))
do
param_unparsed="${SUBMODULES_INFO_ARRAY[chunk+param_i]}"
param_parsed="$(sed -nE 's/^submodule.*?\.'${PARAMS[param_i]}'\s(.*?)$/\1/p' <<< "$param_unparsed")"
SUBMODULES_PARSED_ARRAY+=($param_parsed)
done
process_submodules_parsed_array
done
echo "Restoring .gitmodules"
mv -f .gitmodules.bkp .gitmodules
echo "Initializing submodules"
git submodule init
git submodule update
Short Version
When a build pipeline is triggered, one of the build pipeline task will get the latest files and it has to be added/updated in the git repository of current running pipeline. I tried to do it by using command line task but its failing as not git repository
fatal: not a git repository (or any of the parent directories): .git
Long Version
I m tried to achieve solution pack and unpack process for dynamics 365 instance. So the build pipeline have the following tasks
Export solution from Dynamics 365 and store it in $(build.binariesdirectory)
Unpack the solution zip file and store in $(Build.Repository.LocalPath) i.e., adding/updating existing files
Command line task to commit and push the files to current pipeline repository
ECHO "Setting git config..."
git config --global user.email "xxx#xyz.com"
git config --global user.name "Admin"
ECHO "CHECK GIT STATUS..."
git status
ECHO "GIT ADD..."
git add -A
ECHO "CHECK GIT STATUS..."
git status
ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"
ECHO "Pushing the changes..."
git push -u origin master
ECHO "Customization Committed Successfully"
Updated
If a pipeline is created with 2 command line task i.e. one to create a random file in the Build.Sourcedirectory and another to commit the changes, then the git commit and push commands are working.
But if we add other tasks (such as unzip files in Build.Sourcedirectory directory) before the command line task then getting error as not a repository.
If you see the below screenshot, in the checkout phase the git repo is cloned to D:\a\1\s
And below screenshot is from command line task, where the current working directory is same as the checkout task (i.e., D:\a\1\s) and we can see that the ".git" folder is present so the current directory has local repository in it, but still getting error as fatal: not a git repository
Am I missing anything here?
By default the source files are checked out to the Build.SourcesDirectory (e.g : Directory: D:\a\1\s), it can be considered as a temporary git repository.
According to the error message, it appears that the working directory of the command line task is not under the Build.SourcesDirectory and you did't git checkout again to that working directory.
So, please try unpack the solution zip file and store in Build.SourcesDirectory, then run below Command line to push the commits (it works for me):
ECHO "Setting git config..."
git config --global user.email "xxx#xyz.com"
git config --global user.name "Admin"
ECHO "CHECK GIT STATUS..."
git status
git checkout -b master
ECHO "GIT ADD..."
git add -A
ECHO "CHECK GIT STATUS..."
git status
ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"
ECHO "Pushing the changes..."
git push -u origin master
ECHO "Customization Committed Successfully"
Please note that you need to Grant version control permissions to the build service and enable Allow scripts to access the system token.
i am getting error sh.exe: notepad: command not found please short out my problem
Thanks
For the commit to GitHub part, you need to add (if you have created an empty yourRepo on GitHub):
git config user.name yourGitHubUsername
git config user.email yourGitHubEmail
git add .
git commit -m "First commit"
git remote add origin https://yourAccount#github.com/yourAccount/yourRepo
git push -u origin master
If that fails because GitHub already created one commit when you initialized your "empty" repo (it can add by default a README.md and a .gitignore), do a:
git pull --rebase origin master
git push -u origin master
If you really have to call notepad from a mingw session, you can use this wrapper:
#!/bin/sh
'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar \
-nosession -noPlugin "$(cygpath -w "$*")"
But remember you can use msysgit from a DOS session as well.
Seps:
1.git init
2. git status
3. git add .
4. git commit -a
5. git status
INFO [050fe961] Running mkdir -p /home/rails/rails-
capistrano/releases/20140114234157 on staging-rails
DEBUG [050fe961] Command: cd /home/rails/rails-capistrano/repo && ( PATH=/opt/ruby/bin:$PATH GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/rails/git-ssh.sh mkdir -p /home/rails/rails-capistrano/releases/20140114234157 )
INFO [050fe961] Finished in 0.142 seconds with exit status 0 (successful).
INFO [2dea2fe5] Running git archive feature/Capistrano | tar -x -C /home/rails/rails-capistrano/releases/20140114234157 on staging-rails
DEBUG [2dea2fe5] Command: cd /home/rails/rails-capistrano/repo && ( PATH=/opt/ruby/bin:$PATH GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/rails/git-ssh.sh git archive feature/Capistrano | tar -x -C /home/rails/rails-capistrano/releases/20140114234157 )
DEBUG [2dea2fe5] fatal: Not a valid object name
DEBUG [2dea2fe5] tar: This does not look like a tar archive
DEBUG [2dea2fe5] tar:
DEBUG [2dea2fe5] Exiting with failure status due to previous errors
I am confused about two things:
Why is Capistrano running git archive here:
git archive feature/Capistrano | tar -x -C /home/rails/rails-capistrano/releases/20140114234157
Why is tar failing?
I had the same issue, until I realized I was pulling the nonexistent branch from git.
Deleting app_name/repo also fixed this issue for me.
This happens when the repo in the server to deploy is messed up. We're talking about the bare git repo that Capistrano by default would put in /var/www/$application/repo (for other people's reference).
In your case it does not have a local feature/Capistrano branch so when running git archive feature/Capistrano nothing is output to that | pipe. To confirm, ssh into the server, cd into /home/rails/rails-capistrano/repo, and run git branch.
It's running git archive as a way to export the selected branch's tree. git archive "writes it out to the standard output" so Capistrano redirects that to tar in order to uncompress the archive immediately into your new release directory.
(Why Capistrano chose this instead of git checkout defeats me.)
tar fails because it's receiving nothing d:
I can think of two possible solutions/ways to troubleshoot:
ssh into the server and manually delete the repo folder (e.g. in your case /home/rails/rails-capistrano/repo) as mentioned by #lugolabs
make sure the server's repo is using the remote you're expecting (ssh in, cd into repo/, and run git remote -v) -- you may just need to update your :repo_url in deploy.rb (and delete the repo/ dir).
I think that folder gets populated via a git pull, so it shouldn't be empty. If you do see it empty the issue is from the git not the tarball.
The issue I had was my capistrano deploy.rb repository URL was set to a different one than that project i was working in. In order to fix this issue, I also had to logon to the server and delete the app_name/repo folder which must have been caching the original bad remote URL.
Whenever I have hit this error it was because the branch specified in my deploy/environment.rb file wasn't checked into git. Do an add / commit / git push origin branch_name and that will likely make things work.
You can set your branch on deploy.rb with:
set :branch, "main"
source
Note: the default branch is master
I'm using Bedrock Roots (wordpress) for development, capistrano for deploys and git flow.
Stumbled upon this error when tried to deploy, while on hotfix/x.x.x branch locally. So I finished current (merged changes to develop branch) and then successfully deployed.
How can I create a new repository from my machine using git bash?
I followed the below steps:
mkdir ~/Hello-World
cd ~/Hello-World
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin https://github.com/username/Hello-World.git
git push origin master
But I'm getting "Fatal error: did you run update-server-info on the server? "
You cannot create a repo on github using git bash. Git and github are different things. Github is a platform that let's you host and collaborate on code while git is the version control tool used. You can read more about them on wikipedia articles: github and git.
However if your intention is to create a github repo using terminal, you can do it using the github api and curl.
Probably the easiest way to create a repo on github is somewhere before this line:
git remote add origin https://github.com/username/Hello-World.git
go to https://github.com/new and create a repository on github, then run your last two lines and everything should work.
I have created this bash file to do it all automatically.
#!/bin/sh
reponame="$1"
if [ "$reponame" = "" ]; then
read -p "Enter Github Repository Name: " reponame
fi
mkdir ./$reponame
cd $reponame
curl -u USERNAME https://api.github.com/user/repos -d "{\"name\":\"$reponame\"}"
git init
echo "ADD README CONTENT" > README.md
git add README.md
git commit -m "Starting Out"
git remote add origin git#github.com:USERNAME/$reponame.git
git push -u origin master
So how:
copy the code above. save it as NAME.sh, add it to your PATH. restart terminal or open a new one.
$ NAME newreponame
$ NAME
$ Enter Github Repository Name:
Thanks.
First, try to do this right before the git push:
git pull repo branch
Then try to do the following:
$ git init --bare yourreponame.git
Then do what you were doing before:
touch README
git add README
git commit -m 'first commit'
git remote add origin https://github.com/username/Hello-World.git
git push origin master
I think it is doable.
You can do it using curl (if you are on Windows, you'll have to install it)
curl -u USER https://api.github.com/user/repos -d '{ "name": "REPO" }'
Make sure to replace USER and REPO with your github username and the name of the repository you want to create respectively
It asks for password, input your github admin password and you are good to go.
Actually answered by James Barnett here https://teamtreehouse.com/community/how-does-one-add-a-repository-to-github-using-git-commandline-calls-only
Overview
Command 'git' do not allow you to create repo but it's possible to create new repo at github from BASH script. All solutions use user/password authentication which is deplicated but stil in use. Authentication must be done using personal access token.
Below there are solutions:
3rd party application
https://github.com/github/hub
sudo apt install hub;
cd <folder with code>;
hub init;
hub create -p -d "<repo description>" -h "<project site>" \
"user_name>/<repo_name>";
More options: https://hub.github.com/hub-create.1.html
Pure BASH
REPONAME="TEST";
DOMAIN="www.example.com";
DESCRIPTION="Repo Description";
GITHUB_USER="github_user";
FOLDER="$HOME/temp/$REPONAME";
mkdir -p "$FOLDER"; cd "$FOLDER";
read -r -d '' JSON_TEMPLATE << EOF
{
"name" : "%s",
"description" : "%s",
"homepage" : "%s",
"visibility" : "private",
"private" : true,
"has_issues" : false,
"has_downloads" : false,
"has_wiki" : false,
"has_projects" : false
}
EOF
JSON_OUTPUT=$(printf "$JSON_TEMPLATE" "$REPO_NAME" \
"$DESCRIPTION" "http://$DOMAIN");
# https://developer.github.com/v3/repos/#create-an-organization-repository
curl -u ${GITHUB_USER} https://api.github.com/user/repos \
-d "$JSON_OUTPUT"
just try to add -u in your last line:
git push -u origin master
Maybe you are getting this error because you didn't set your identity:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe#example.com
Here you can find the steps to create and put your repository on github:
http://programertools.blogspot.com/2014/04/how-to-use-github.html