git: creating remote branch failed - linux

I tried creating remote branch devel using:
git push origin origin:refs/heads/devel
But it fails with:
error: src refspec devel does not match any.
error: failed to push some refs to 'git#***.com:***/abcd.git'
What's going on?
EDIT:
I am following: This Tutorial

If devel is your local branch, then this is sufficient:
git push origin devel
Your example doesn't work, because you try to push "origin" branch to remote repository ("origin"), but you don't have branch named "origin" (first origin here) in local repository.
You can run:
git push origin devel:refs/heads/devel
# ^ ^
# | +---- it's ref for remote branch to create
# +---------- it's local branch name
This second form is preferred if you local branch name should differ from remote branch name.

Did you make sure to do git add to all of your files first. Then git commit then git push?

Related

gitolite: error: src refspec master does not match any

I have created an empty git repository by use of gitolite and cloned it to my laptop. Usually, I can add files to it on my laptop on and push them to the repo but now an error occurs:
user#laptop Myproject % git clone newergit:Repo-Myrepo
Cloning into 'Repo-Myrepo'...
warning: You appear to have cloned an empty repository.
user#laptop Myproject % cd Repo-Myrepo
user#laptop Repo-Myrepo % vi test.txt
user#laptop Repo-Myrepo % git add test.txt
user#laptop Repo-Myrepo % git commit -m "add test file to repo"
[main (root-commit) 27aa970] add test file to repo
1 file changed, 1 insertion(+)
create mode 100644 test.txt
user#laptop Repo-Myrepo % git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'newergit:Repo-Myrepo'
This used to work in the past but newly I am experiencing this error and don't know how to proceed?
Unfortunately, git branch -al did not resolve the problem
A git branch -avv is only there to list the local and remote branches, for you to understand which branch was created (locally by your git commit and remotely by Gitolite)
If you use Git 2.37+, you can activate the
git config --global push.autoSetupRemote true
From there, a simple git push (without any additional parameter) should be enough. It will pick the right branch name (the current one) and push it to the remote with remote tracking.

git#gitlab.com: Permission denied (publickey,keyboard-interactive)

I have a Gitlab repository that contain a number of projects on all of which I can pull and push documents to with Git Bash. I want to set up new project. On the Gitlab website I have created the new project and am following the usual instructions in Git Bash:
cd existing_folder
git init
git remote add origin git#gitlab.com:new_project_name.git
git add .
git commit -m "Initial commit"
git push -u origin master
However when I try push (the last line of the above I get the error:
$ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'git#gitlab.com:new_project_name.git'
(NB: the project name has been replace in this post by new_project_name)
There is a readme file that is ready to be committed.
I know I've missed something or done something incorrectly but I don't know what. I don't understand why I can push to other projects (the pull/ push is working fine) but not this one. What do I need to do in order to git push to the repo?

Error in Github when I do "git push origin master" (error: src refspec master does not match any)

My branch in the Github repository is "master". In the terminal I did:
git branch
and the output is:
* main
my-temporary-work
I wanted to push a file to Github and I used:
git add exploratory_analysis.ipynb
git commit -m "New version"
git push origin master
The "git add" and "git commit" commands work. However, the last command (i.e., "git push origin master") does not work, and I get this error:
error: src refspec master does not match any
error: failed to push some refs to 'git#github.com:NAME-OF-USER/REPOSITORY-NAME.git'
That is, it looks like I cannot push any code from my laptop to Github. How can I fix it?
I faced the same issue some days ago.
If you created a new repository nowadays(2020) then the default branch in main on GitHub.
you can check on GitHub now in your repository branches.
so that's why you need to run
git push origin main
instead of
git push origin master
Goodluck with more details you can watch video
Why are you pushing to master if the branch commands outputs main? Try 'git push origin main'
Also found this explanation for the change:
https://stackoverflow.com/a/65008828/1959534

can't push to gitlab, failed and rejected

has been pulled, the result is still an error ! [rejected] dev->dev(non-fast-forward)
D:\PPI_Roketin\Project\astrowatch (dev)
λ git add resources/views/reals/_form.blade.php
D:\PPI_Roketin\Project\astrowatch (dev)
λ git commit -m "resources/views/reals/_form.blade.php"
[dev db5ac99] resources/views/reals/_form.blade.php
1 file changed, 2 insertions(+), 2 deletions(-)
D:\PPI_Roketin\Project\astrowatch (dev)
λ git push origin dev
To gitlab.com:roketin-stellar/astrowatch.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'git#gitlab.com:roketin- stellar/astrowatch.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.
error like this, why?
have done git checkout, and repeated the command, it's still an error like above
This is a classic git error. The problem is described in the error message: Updates were rejected because the tip of your current branch is behind, which means that there have been changes to the remote branch that you do not have locally. There are quite a few ways to fix this, one of which is also described in the git message: Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.
If you do git pull origin dev this will merge whatever changes are made in the remote to your local branch. Once you fix the merge conflicts, you can then push the branch.
Another option would be to run a rebase by performing git pull --rebase origin dev, which will bring in the remote changes and rebase your commits on top of the remote commits. This will result in a cleaner git history.
The easiest for now would probably just doing a git pull, then once it's merged correctly, pushing to your remote.
I definitely recommend researching the git commands and learning how to find the resources correctly in the docs. There is a lot available online.
you can try git reset --hard HEAD
please remind that:
HEAD points to your current branch (or current commit), so all that git reset --hard HEAD will do is to throw away any uncommitted changes you have.
It's quite self explanatory, you need to keep yourself upto date with remote branch if you want to commit and it looks like git pull will overwrite files you've made changes to. You should commit your changes first.

Git push to local repo says "everything up to date", it isn't

I have a theme I use for our merchant store. I use git to maintain a repo (local repo 1) of this theme that i clone into a dev folder (local repo 2) and then work on there, when I'm done I want to update (push?) to the original local repo 1. From there I can render zip files or whatever I need for the merchant store.
So i made repo1 by git init and adding the files and committing it. worked fine. Then I cloned the repo to my dev folder and setup my web services there. Worked great. I edited my theme and made commits appropriately. Now that I am ready to put these changes on the live server I want to push to my origin which should be repo 1. However after making commits when I try to push from repo2 by
git checkout master
and then
git merge classes-migration
and then
git push
it says "everything up to date" I've tried specifying specifically the same branch to push, honestly I've tried all kinds of things reading through the different answers here.
git branch [for repo1]
classes-migration
import-classes-migration
initial-commit
* master
git status [for repo1]
On branch master
nothing to commit, working directory clean
git branch [for repo2]
classes-migration
* master
git status [for repo2]
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
git remote show origin [for repo2]
* remote origin
Fetch URL: /home/user/projects/merchant/repos/theme
Push URL: /home/user/projects/merchant/repos/theme
HEAD branch: master
Remote branches:
classes-migration tracked
import-classes-migration new (next fetch will store in remotes/origin)
initial-commit tracked
master tracked
Local branches configured for 'git pull':
classes-migration merges with remote classes-migration
master merges with remote master
Local refs configured for 'git push':
classes-migration pushes to classes-migration (up to date)
master pushes to master (up to date)
So.. yeah.
The push command is used to put in the server what you already has committed.
If you have a git repository configured, clone it in your dev machine, then work in this project. After that you need to commit your changes.
first check the status after the changes:
git status
If you get this message
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: filename.txt
no changes added to commit (use "git add" and/or "git commit -a")
It means you`ve changed the file filename.txt, if you've changed more then one file, every file will be listed here.
The next step is commit the file.
git commit filename.txt -m "commit comments"
Just after that, you push to the server:
git push
After this command, when you clone in another machine or update the repository the user will see the modifications.

Resources