1

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.

Reowald
  • 41
  • 7
  • What do `git remote` and `git branch -r` show? – Felix Kling Jul 04 '19 at 10:02
  • Neither show anything - no feedback from these commands – Reowald Jul 04 '19 at 10:08
  • First you should setup the `origin` remote correctly, which does not appear to be the case. Issuing `git remote -v` will show you the remotes setup. To create the origin alias for your remote repository, use `git remote add origin git@gitlab.com:group/project.git` – Yannoff Jul 04 '19 at 10:10
  • That would mean that your local repo is not even connected to the remote repo. That's why you cannot pull. However, I wonder why `git ls-remote` works then. – Felix Kling Jul 04 '19 at 10:18

4 Answers4

1

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 :)

Yannoff
  • 367
  • 2
  • 9
  • $ git fetch somelongcode fatal: somelongcode 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. – Reowald Jul 04 '19 at 10:09
  • You should set your remote first... See my comment in the main section – Yannoff Jul 04 '19 at 10:11
  • @Reowald did you make it to configure your remote properly? – Yannoff Jul 04 '19 at 10:48
  • Still struggling: $ git fetch 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. (thanks for your amazing help) I am not exactly sure what you mean by 'set' remote – Reowald Jul 04 '19 at 11:01
  • OK, I think you should really take a look at the documentation link I've included above. https://www.atlassian.com/git/tutorials/syncing It's all explained, and in a very clear manner. – Yannoff Jul 04 '19 at 11:06
  • 1
    Thanks @Yannoff really helpful - annoyingly it has all been working perfectly until a contract developer turned up and it all wen to pot! :) (of course it did) – Reowald Jul 04 '19 at 11:09
  • I know this thread is quite old now but it hit 1k and I re-read it. I don't think I was setting up the origin remote as you clearly stated in your first post. Secondly, I have been setting up projects via the website rather than through bash which has irradicated any misuse! – Reowald Sep 06 '21 at 15:57
1

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>.

tenni
  • 475
  • 3
  • 11
  • You are correct, I was not setting up the remote correctly. Sorry for the delayed response but this thread just hit 1k and forced me to review it. – Reowald Sep 06 '21 at 17:06
1

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
1

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

Reowald
  • 41
  • 7