git push --mirror - internal server error - linux

I have created a git repo using (GIT API) and initiated it with git init. (but no git add or git commit command) . when i try to use the git push --mirror , it gives internal server error.
I saw the following bug (100+ ref will give internal server error)
https://github.com/isaacs/github/issues/1253
even my repo got 500+ refs.
Do i need to use git add and git commit to push the repository to github with mirror command ?
when i do the git add and git commit on local repo, i can push the content.
I'm doing all those using the API, and is it possible to use git push --mirror without any git commit or git add commands?
When i go to the remote repo, i can see the GitHub quick setup page, asked to execute git add, commit etc...
my questions is how should i avoid that GitHub quick setup page,and push my contents to the remote repo without executing git add, or git commit ?

I don't understand what's your content.
If you have file and don't add them and don't commit, you have no content, as far as git is concerned.
You need to have at least a commit to push your repository, otherwise you're pushing nothing.

Related

problem with my git repo, I lost all my commits?

I was trying to upload a file via terminal.I am trying to learn git.
**
git add /Users/serra/Documents/useSDWebImage
git commit -m "learning on process"
git remote add origin
git push -u origin master
**
then I got this message error: failed to push some refs to ....
I tried those commands then I have only the file I want to upload
to repository I have lost rest of the repository.What should I do?
**
git pull --rebase origin main
git push origin main
git pull origin master
git push origin master
git push origin master --force
**
TL;DR
You need to find a backup, somewhere, of origin/master.
git reflog might help you.
The error
First, let's go over your first four commands and explain what the mistake was.
In the first two commands, a git add and git commit, you are creating a commit in your local sandbox, building on whatever was in your sandbox beforehand.
In the third command, you add your remote, which means that your commit was not made on top of that remote, but on top of something else.
In your fourth command, Git correctly tells you that you cannot push, because your local sandbox is not built on top of the remote. It's important to pay attention to Git's error messages, they're almost always informative.
Now, you're not showing outputs from any of the commands you ran, but I'm guessing git push origin master --force is what deleted stuff on your remote.
What you should have done
Normally, you clone the remote first, then commit stuff on top of it:
git clone <URL>
cd <SANDBOX_DIR>
git add <file inside this directory>
git commit
git push
How to fix this
There are several ways, but they're all based on recovering stuff from a backup that hopefully exists somewhere.
If your remote is GitHub, it keeps a history of references, you should be able to find that old master branch somehow there. If your remote is some other server, that is hopefully true too. If another team member has a sandbox that had the valid master you want to restore, they can fix things by doing a git push origin master --force in their own sandbox, but make sure they understand what they're doing before they do it.
My answer here is not complete, because you didn't provide enough information. I will update it if you update your question with more details about your remote.
Update - git reflog might help
When you did git pull origin master, assuming master is the branch you care about, you probably got a local copy of the correct master commit you want on origin. You can use git reflog to see the history of your local HEAD in your sandbox. If you find the good commit there, this solution could work:
Here I'm assuming these is not work you want to preserve in your sandbox.
git checkout master
git reset --hard <good commit> # WARNING: destroys any uncommitted local changes
At this point, check that your sandbox contains the files you want to restore to origin. If so, proceed with this command:
git push --force origin master
But be warned, this will overwrite what's on origin. It's only appropriate if you have carefully validated that master in your sandbox really contains the history you want to restore on origin.

How to git push to two repositories while git pull from one repository

I'm working on linux server (non-desktop) and I have two repositories. One is for development (github), the other is a local repository of my lab (gitlab).
What I need is to keep the two repositories always exactly the same, and I can push and pull on my dev repository, whereas only push on my local repository so that my colleagues can git pull from my lab repository. My lab-repository is used only for sharing my project with my colleagues: I do nothing but git push and they do nothing but git pull. That's all.
Well, you may ask why don't use the dev repository. That's because they have no right to connect to the Internet.
I don't like to execute many commands for each action. For example, for now I have to execute the commands below to git push to the two repositories:
cd devRepo
# coding here
# git add & git commit & git push here
cd ../myLabRepo
cp -r ../devRepo/* ./
# git add & git commit & git push here
This is kind of boring. Ofc, I know I can use bash script but I'm wondering if there are some specialized tool to do so or maybe Git has the capacity to do so.
You can specify more than one push location for the same remote.
git remote set-url --add --push <remote name> <push url>
Check this with git remote -v
You should see the original push and fetch URLs, along with the extra push URL you just added.
You can add the whole stuff that you have into a bash script and run that. Otherwise, you can add a remote to your first repository and do a push there as well, instead of copying your whole project.
git add & git commit & git pull origin master & git push origin master & git push local master

Cannot clone git repo inside existing checked out git repository

I am trying to clone my a git repository inside an existing checked out git repository and getting this failure. I've done this workflow before so I cannot figure out why it would fail now. Does anyone have any suggestions?
The git repository does exist and I can clone outside of the checked out repository in a different location
Let's say I do the following
1. cd <existing git repo clone folder>
2. git clone https://github.com/apache/cassandra
Cloning Git Repository of cassandra
Cloning into 'cassandra'...
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
What could be causing this error?
PLEASE NOTE - I DO NOT WANT TO ADD THIS REPOSITORY AS A SUBMODULE TO MY PARENT GIT REPO. I simply want to figure out how to clone the repository in an existing working folder checked out from git.
Have a look at git submodules This was designed exactly for this. You can find information and examples here: https://git-scm.com/book/en/v2/Git-Tools-Submodules
In your case, this might work:
git submodule add https://github.com/apache/cassandra
In order to change the submodule to track a particular commit change directory to the submodule folder and switch branches as normal.
cd submodule
git checkout -b some_branch origin/some_branch
or for some particular tag
git checkout <version_tag>
You will need to commit this change to update.
Your question sort of seems to be in conflict. You can't have a git repo within another git repo without using git submodules AFAIK.
What you could do is have a dir that is not a git repo, and clone both the repos into that dir (so don't put the repos inside each other).
You could also add the repository as a remote (using git remote add name_of_remote http://your/remote/here). Then you can checkout any branch from either repo in the same repository.
I usually do not like to use submodules. for this case I would do the following:
1) in the main repo .gitignore the folder path where you want to store the repo the path-of-cassandra-repo/* (to ignore it)
2) in the terminal execute git clone https://github.com/apache/cassandra.git path-of-cassandra-repo/ where "path-of-cassandra-repo/" the name of the folder you want git to store the repo.
3) you are ready to go... Happy coding.
Let me know if this works for you...

Can't find my git repository url

So I think I am confused - but for some reason I cannot push or pull to my git repository.
I have a linux web server and have a web folder in /var/www/bcs.net.nz/
I did a git init bcs.git in this folder (I have also tried .git)
and then I thought I could do git clone git#bcs.net.nz:bcs.git to clone it on the local machine or git push on the remote machine.
I have also added a git remote add origin git#bcs.net.nz:bcs.git on the remote machine.
After all of that I still cannot push and pull anything.
I am a bit stuck.
git add . & git commit -m "initial commit" work fine.
git clone git#bcs.net.nz:bcs.git would mean to clone a (preferably bare repo) which is in /home/git/bcs.git
You could initialize one there, (git init --bare /home/git/bcs.git), and add a post-receive hook (chmod 755 /home/git/bcs.git/hooks/post-receive) which will checkout the code in the live server folder
#!/bin/sh
git --work-tree=/var/www/bcs.net.nz --git-dir=/home/git/bcs.git checkout -f

Added BitBucket repo as remote on GitHub

I've just installed git on Ubuntu, now I want to work on my repo in BitBucket. I'm a little confused on how to do so. I can't do the following:
git remote add BitBucketRepo git#bitbucket.org:dir/file.git
As it returns the following error:
fatal: Not a git repository (or any of the parent directories): .git
It clearly is pointing to a git repo, so why is it lying to me?
Also, it is worth noting I am using SSH and I have successfully paired my GitHub account to my computer.
You need to run this command from a local git repository (a directory in which you have run git init or git clone) - otherwise git remote doesn't know which local repo you want to add the remote for.
It should be as simple as cd my-local-dir, where my-local-dir is the directory containing your local (cloned) git repository.
If you don't yet have the repo available locally:
git clone git#github.com:...etc... my-local-dir
cd my-local-dir
git remote add ButbucketRepo git#bitbucket.org...
git push -u ButbucketRepo master
This will clone your code from Github into the my-local-dir directory, add your BitBucket repo as a remote repository, push your code up to Bitbucket and set the local master branch to track the BitBucket remote's master branch.
Tracking means that commands that involve a remote like git push will automatically use the BitBucket remote's master branch. If you don't want that behaviour, skip the -u option.

Resources