Git Bash Fatal:Could not read from remote repository - windows

So I have a git repo set up on a linux machine and I typed
git remote add test git#*****.com:/opt/git/project.git
and then I did
git init
git add *
git commit -m 'Blah blah'
When I go to do
git push remotename
I get fatal:Could not read from remote repository.
I know it is a problem on my side, because my friend can on his arch linux machine. I have private ssh keys in a different folder then my git bash and then I have public keys in the git user home folder all set up. I don't know if I need to set up SSH keys somehow with git bash or something.

You need to add the upstream repo as a remote
git remote add remotename git#*****.com:/opt/git/project.git
And now do a push
git push remotename
PS : The step where you ran git add git#*****.com:/opt/git/project.git was meaningless, and should have thrown you an error ideally.

Related

How can i upload a Spring Java project to GitHub so i can show my work?

I've tried through various ways, directly uploading the files wont work. I've tried through bash and nothing.
Do you have git installed?
# Create a new repository on the command line
#Go to Project Directory on your Computer, Open git Bash here
# run the following 1 by 1
git init
git add .
git commit -m "Comment here"
git remote add origin https://github.com/YourRepoPrefixHere
git push -u origin master
If you have a git profile and a repository you can take these simple steps to get it online:
Open a terminal and go inside the folder of the project you want to push to your git repository
Check if you are on the right git branch: git checkout
git add .
git commit -m "your messagge to commit"
git push origin -u "yourbranchName
If you have never set up your origin branch, you should add it before using it:
git remote add origin "github link"
To see if everything went well you can do a simple: git status.
I hope it will be useful to you my friend!

Local repository is not able to pull branch from remote repository

I have been using GitLab successfully with another onsite developer with small projects in C and MATLAB.
Working from home using a VPN I pushed a large LabVIEW program into a fresh project so I can work alongside another off site developer. The developer cloned the project and began work on a branch.
The issue is I have not been able to pull/fetch this branch. GitLab is showing the branches and commits that the developer has made.
I have not been long using git and so I may just be being stupid.
Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."
I have looked at this in particular but have not made it work, below are some of the things I have tried.
$ git remote remove somelongcode
fatal: No such remote: 'somelongcode'
$ git remote add origin
usage: git remote add [<options>] <name> <url>
-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=(push|fetch)]
set up remote as a mirror to push to or fetch from
$ git remote master --prune
error: Unknown subcommand: master
usage: git remote [-v | --verbose]
or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
or: git remote rename <old> <new>
or: git remote remove <name>
or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
or: git remote [-v | --verbose] show [-n] <name>
or: git remote prune [-n | --dry-run] <name>
or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
or: git remote set-branches [--add] <name> <branch>...
or: git remote get-url [--push] [--all] <name>
or: git remote set-url [--push] <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>
-v, --verbose be verbose; must be placed before a subcommand
________________________
$ git fetch origin master
fatal: 'origin' 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.
________________________
$ git reset --hard origin/master
fatal: ambiguous argument 'origin/master': unknown revision or path not `in the working tree.`
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
I can see the branch in remote. This is the most encouraging at least I can see the remote even if I cannot sync with my local repository
$ git ls-remote
From git#gitlab.com:group/project.git
somelongcode HEAD
somelongcode refs/heads/apploc
somelongcode refs/heads/master
As you can see locally I cannot see the branch
$ git pull
From gitlab.com:group/project
* branch master -> FETCH_HEAD
Already up to date.
$ git branch
* master
$ git remote show origin
fatal: 'origin' 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.
The structure of any git repo is the same wherever you go, you can check your local branches under the folder .git/refs/heads or by using the command git branch.
As for what's in the remote declared in your repo, you can see that in .git/refs/remotes/ or by using the command git branch -a and check the red colored lines.
Now to the subject at hand, any git repo needs to know the url and the name of whatever remote you're going to use, and you can use git remote to manage that. So if you want to list them use git remote,
to list Up and Down stream of each one use git remote -v, and
to add a new remote use git remote add <remote_name> <remote_url>.
The remote url is composed as follows if you are using ssh git#<server_address>:<name_space>/<repo_name>.git so it's composed of:
server address which if you're using gitlab is gitlab.com,
name space which is group as you mentioned, and lastly,
repo name which in our case is project but you still need the .git extension at the end of the url.
You can also copy the url from the gitlab interface by clicking on the clone button which will show you the url with ssh and another with https.
Now if you configured your remote correctly you will need to refresh your local repository with what's in the remote by using the command git fetch <remote_name> and that will download all the branches from the remote to your .git/refs/remotes/ folder, Then if you have a branch that's there and doesn't have any mirror branch in local (.git/refs/heads) you can create it yourself to be able to add other commits on top of it by using the command git checkout -b <branch_name> <remote_name>/<branch_name>.
Try the below
$ git remote add origin remote/repository/URL
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
Then
git pull origin branch_name
Hi #Yannoff and anyone else who looked at this. Thanks for you help. I think I tried nearly everything with Bash. I cloned the project on another machine and it all worked as expected. I then cloned it again on my machine and again everything worked fine. It was my original local repository that was causing the issues. I wonder whether working from home over VPN had an effect? Everything works now but not my original local repo.
However I am now clearer on how it all works with the help of the web links you gave me so it has not all been in vein!
*** I was not setting up the remote origin correctly see Yannoff's advice and the accepted answer for reasoning.***
Very good website - https://www.atlassian.com/git/tutorials
To synchronize your local repository branch list with the remote one, use git fetch
So your command should be something like:
git fetch somelongcode
Then you should have the up-to-date branch list :)

How to publish Github repository

I need to publish a Github repository from a directory on my computer.
I added, committed, and pushed the origin master of the files I wanted to publish from the root directory of my project. By that, I mean I clicked the "create a new repository" button and typed all the git commands in my terminal while in the project directory I want to publish as my repository. For a list of the commands I used, see the below section labeled "Code."
I saw no errors during the terminal commands. When I finished, all I saw in my repository was the README.md file and nothing else.
I tried to check at my terminal to see if my login name matched the Github username of the target repository. But I didn't see any commands for checking the login name at the terminal.
OS/config: Using OS X 10.10.5 (Yosemite) on MacBook Air
Code
I tried this...
git init
git add README.md # This is the problem. (See my answer below.) Should be "git add ."
git commit -m "first commit"
git remote add origin https://github.com/"username"/"repository".git
git push -u origin master
Heres a basic push to GitHub, What kind of errors are you getting?
create a new repository on the command line
git init
git add . //This will add everything in the directory
git commit -m "first commit"
git remote add origin https://github.com/"username"/"repository".git
git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/"username"/"repository".git
git push -u origin master
Here is what solved the problem for me...
That second git command line should be git add . not git add README.md. The . adds all the files in the directory, as mentioned by the accepted answer.
Code
Solution
git init
git add . # This was the key line to change from what was tried in the question.
git commit -m "first commit"
git remote add origin https://github.com/username/repository
git push -u origin master

converting a local git folder as a remote repository

sorry if my question is too naive. Here is what i am trying to do:
I want to create a local git repo (git init )-> i did that
I want to access the same form other machines using ssh -> stuck here
I have tried installing git bash , but i don't know how to configure ssh which is built in the git bash.
I did add a ssh config file using git bash and gave as my computername along with domain, since this machine is the server here.
In the git bash guide, they are adding the public key to github, i dont want that
In short i have created a git repository by 'git init .'
I want to access the same using other machines in the same domain using ssh
I don't know how to proceed further, Would anyone be able to help in this case ?
I'd create a --bare repository somewhere accessible via SSH and push, fetch, merge, pull to and from that repository by adding a remote origin to the ones you created.
Something like
/home/git $ git init --bare your_repository.git
/your/current/repository $ git remote add origin /home/git/your_repository.git
And from another machine
/client/path $ git init
/client/path $ git remote add origin user#server:/home/git/your_repository.git
/client/path $ git pull origin
Then
/your/current/repository $ git fetch origin
/your/current/repository $ git merge origin/master
/your/current/repository $ git push origin master
/client/path $ git fetch origin
/client/path $ git merge origin/master
/client/path $ git push origin master
That's just an example, the --bare repository can be anywhere.
Have a look here for pros and cons http://git-scm.com/book/ch4-1.html

Git server and clone

I have create my git server with this link link
git clone working in server but when i clone my project on local machine
i have a problem
"warning: remote HEAD refers to nonexistent ref, unable to checkout."
i used for clone "git clone http://domain.com/project.git"
i used virtual machine(domain.com =192.168.1.196) for git server and windows for local machine.
Thanks
On the server run the following command in a new folder to initialize a new bare git repo...
git init --bare
On your local machine go to an existing folder of create a new one and run.
git init
Copy a file into this folder and execute.
git commit -am "New repository with a new file"
Then add your server as a remote.
git remote add myserver http://domain.com/project.git
Next step is to push to your server.
git push -u myserver master

Resources