Ошибки Git

fatal: No such remote 'origin'

fatal: No such remote 'origin'

Скорее всего Вы пытаетесь выполнить

git remote set-url origin https://github.com/name/project.git

Попробуйте сперва выполнить

git remote add origin https://github.com/name/project.git

error: failed to push some refs to

To https://github.com/YourName/yourproject.git
! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/YourName/yourproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Скорее всего Вы пытаетесь выполнить

git push origin master

в новом репозитории.

При этом, когда Вы создавали удалённый репозиторий на github Вы отметили опцию initialize with readme file.

Таким образом на удалённом репозитории файл README.md есть, а на локальном нет. Git не понимает как такое могло произойти и предполагает, что на удалённый репозиторий кто-то (возможно Вы) добавил что-то неотслеженное локальным репозиторием.

Первым делом попробуйте

git pull origin master

git push origin master

Git скачает файл README.md с удалённого репозитория и затем можно будет спокойно пушить

Если сделать pull не получилось, например, возникла ошибка

From https://github.com/andreiolegovichru/heiheiru
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories

Попробуйте

git pull --allow-unrelated-histories origin master

git push origin master

ERROR: Permission to AndreiOlegovich/qa-demo-project.git denied to andreiolegovichru. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

Возможная причина - git не видит ваш ключ. Либо ваш ключ уже используется для другого удалённого хранилища.

Решить можно удалив стандарный ключ id_rsa.pub создать новую пару и добавить на удалённое хранилище.

Если этот способ не подходит - нужно настроить config.

fatal: Could not read from remote repository

no such identity: /c/Users/Andrei/ssh/github: No such file or directory git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

Первым делом нужно проверить - добавлен ли ключ на удалённый репозиторий. Включен ли SSH агент и добавлен ли в него этот ключ

eval `ssh-agent -s`

Agent pid 1234

ssh-add ~/.ssh/id_rsa

Identity added: /c/Users/Andrei/.ssh/id_rsa (AzureAD+Andrei@AredelComLap0141)

Команда, с помощью которой можно проверить корректность вашей конфигурации

ssh -T git@github.com

Warning: Permanently added 'github.com' (ED25519) to the list of known hosts. Hi AndreiOlegovich! You've successfully authenticated, but GitHub does not provide shell access.

fatal: repository 'x' not found

Если вы получили ошибку

fatal: repository 'x' not found

Под Windows - попробуйте удалить существующие git credentials

Control Panel → User Accounts → Credential Manager (Manage your credentials) → Windows Credentials

Всё что связано с Git или GitHub нужно удалить (на ваш страх и риск)

error: unable to create file Filename too long

Если вы получили ошибку

error: unable to create file Filename too long

Первое, что советую сделать - проверить разрешены ли длинные пути в gitconfig

Если нет, то разрешить их можно командой

git config --system core.longpaths true

В Windows файл gitconfig находится в директории

C:\Program Files\Git\etc

[diff "astextplain"] textconv = astextplain [filter "lfs"] clean = git-lfs clean -- %f smudge = git-lfs smudge -- %f process = git-lfs filter-process required = true [http] sslBackend = openssl sslCAInfo = C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt [core] autocrlf = true fscache = true symlinks = true fsmonitor = true longpaths = true [pull] rebase = false [credential] helper = manager [credential "https://dev.azure.com"] useHttpPath = true [init] defaultBranch = master

Если вы работаете в Windows нужно разрешить использование длинных имён файлов.

Error cloning remote repo 'origin'

Если вы получили ошибку

Cloning the remote Git repository ERROR: Error cloning remote repo 'origin' hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- git@github.com:AndreiOlegovich/robot_web_ui_test.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

error: Your local changes to the following files would be overwritten by checkout",

Означает, что вы внесли изменения в файл в какой-то ветке, и хотите сделать чекаут в родительскую, например в master, но кто-то уже поменял этот файл в родительской ветке и вам нужно либо закоммитить его в свою ветку, чтобы дальше он отслеживался там, либо сбросить его в stash

fatal: The current branch main has no upstream branch

Скорее всего эту ошибку вы увидели выполнив

git push

fatal: The current branch main has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin main

Например, вы могли создать новый репозиторий на GitHub, привязать его к существующему локальному репозиторию, но не сделать git push с опцией -u при первом пуше.

Перед тем как делать push с опцией -u нужно указать путь до ключа, иначе получим следующую ситуацию :

git push -u origin main

Username for 'https://github.com': AndreiOlegovich Password for 'https://AndreiOlegovich@github.com': remote: Invalid username or token. Password authentication is not supported for Git operations. fatal: Authentication failed for 'https://github.com/AndreiOlegovich/merge_demo.git/'

В этом случае нужно сделать две вещи, если они не были сделаны ранее: создать и добавить SSH ключ, подключить удалённый репозиторий по SSH url а не по HTTPS

cd ~/.ssh ssh-keygen -t ed25519 -C "username@email.ru" eval `ssh-agent -s` ssh-add ~/.ssh/id_ed25519 cat ~/.ssh/id_ed25519.pub git remote set-url origin git@github.com:AndreiOlegovich/merge_demo.git git push -u origin main

Warning: Permanently added 'github.com' (ED25519) to the list of known hosts. Enumerating objects: 15, done. Counting objects: 100% (15/15), done. Delta compression using up to 24 threads Compressing objects: 100% (13/13), done. Writing objects: 100% (15/15), 1.49 KiB | 1.49 MiB/s, done. Total 15 (delta 3), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (3/3), done. To github.com:AndreiOlegovich/merge_demo.git * [new branch] main -> main Branch 'main' set up to track remote branch 'main' from 'origin'.

Автор статьи: Андрей Олегович