Unable to Git push to a remote branch (not master) from azure pipeline - bash

I have been trying to do a Git Push from a bash task on Azure DevOps. I was already pushing the code to the master branch without any issues.
But now I have to push it to the dev branch, and for some reason, Git Pull works but not Git Push. These are the steps I followed. I tried various versions of this actually, but nothing worked.
git config --global user.email "xxx#gmail.com"
git config --global user.name "abc"
git pull https://PAT#github.com/repo.git HEAD:dev
git add $PROXYNAME
git commit -m 'Auto-checkin of $PROXYNAME proxy to Git'
git show-ref
git push https://PAT#github.com/repo.git HEAD:dev
The above worked when the push / pull had HEAD:master at the end.
This is the error I have been getting each time.
To https://github.com/repo.git
! [rejected] HEAD -> dev (non-fast-forward)
error: failed to push some refs to 'https://***#github.com/repo.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Edited to add:
I have also tried with a checkout command - to checkout that dev branch, and no luck!
Result of git remote -v:
origin https://github.com/repo (fetch)
origin https://github.com/repo (push)
The latest error am getting is below:
error: src refspec dev does not match any
error: failed to push some refs to 'https://***#github.com/repo.git'
Could anyone please let me know what I need to do to get this working. This seems to be a recurring issue for me now :(

I believe you need to configure git remote to your correct repository.
The result of git remote -v should refer to your current directory remote association.
Start with git remote --help
Especially:
git remote set-url [--push] [] git remote
set-url --add [--push]
Here is a good tutorial on git remote.

Related

why the branch does not appear to be a git repository? it is not the master branch

I don't know what I did something to change the configuration of the git setting.
When I use 'git push dev master', there is an error below, but this instruction is working before.
$ git push dev master
fatal: 'dev' 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.
This is the setting and configuration of my repository and branches
$ git remote -v
origin https://git.heroku.com/main_project.git (fetch)
origin https://git.heroku.com/main_project.git (push)
$ git remote show origin
* remote origin
Fetch URL: https://git.heroku.com/main_project.git
Push URL: https://git.heroku.com/main_project.git
HEAD branch: master
Remote branches:
backup tracked
dev tracked
development tracked
master tracked
refs/remotes/origin/fullcalendar stale (use 'git remote prune' to remove)
repeat_reminders tracked
stable tracked
weekly tracked
Local branches configured for 'git pull':
dev merges with remote dev
master merges with remote dev
Local refs configured for 'git push':
dev pushes to dev (up to date)
master pushes to master (up to date)
$ git branch -a
dev
* master
remotes/origin/backup
remotes/origin/dev
remotes/origin/development
remotes/origin/fullcalendar
remotes/origin/master
remotes/origin/repeat_reminders
remotes/origin/stable
remotes/origin/weekly
I searched for some solutions such as 'set-url' or add origin, such below
But they are not working either.
git branch --set-upstream-to=origin/dev master
git remote add origin https://git.heroku.com/dev.git
fatal: remote origin already exists.
Please help this questions.
Thank you very much.
What are you trying to achieve? First, you have a single remote called origin set up. When you run git push dev master you are asking git to push a local branch called master into a remote branch with the same name on a remote that is called dev. Given that you only have origin set up, don't expect git to be able to comply. If what you want to do is push two branches, namely dev and master, to origin, you should run:
git push origin dev master
If what you want to do is push your local dev branch to the remote master branch, you should do
git push origin dev:master
Or is there anything else you are trying to do?

BitBucket - error: failed to push some refs

I have some projects I would like to upload on my bitbucket private profile. I performed the following steps but I get an error.
Convert my project to git with: git init
Next:
git add
git commit -m "some message"
I created a bitbucket repository and version control system is GIT.
I then type this (of course with real account name and reponame and repo owner):
git remote add origin https://<repo_owner>#bitbucket.org/<accountname>/<reponame>.git
Finally,
git push -u origin master
I did all of this and my terminal gives me this error:
To https://bitbucket.org/milosdev_me/lfs.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://milosdev_me#bitbucket.org/milosdev_me/lfs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Try:
git push origin master --force
This works for me.
Your master branch has some code that you don't locally have, and to prevent you from conflicts, it doesn't let you to push further changes, before you have them locally. To resolve this, pull all the changes to your local repository (your project):
git pull origin master --allow-unrelated-histories
After that, you will have all the code that is available on your master branch.
NOTE: Be careful, pulling the code from remote branch might mess up all the changes locally. Make sure to save those changes somewhere, or create another branch locally where you will pull your origin master branch, so it doesn't mess up your changes.
Your issue is that you have different things between your local repository and your git repository (probably a readme file that you created automatically), so you have two options:
use git pull origin master, with this command, you will pull from your git repository, but it will cause a merge conflict, which you have to resolve using an IDE (recommended to beginners) or through cmd.
use git push origin master --force, this way, you will force your push from your local repository to your git repository, ignoring any merge conflict by overwriting data. I'm not sure, but I think it will overwrite all git repository data with you local repository data (which is what you want).
Adding --force option is a bad idea
Either rebase it or pull the code, merge it and push it.
git pull --rebase origin master
git push -u origin master
Your remote repository and local repository have differences, something new in remote repository. So for pushing you need pull changes, from remote, previously. Try do:
git pull
git push -u origin master
The issue is because your remote repository and local repository have differences.I had same issue and i tried all the above mentioned solution but nothing worked for me.
For me the scenario was :- I already had my branch in remote repository.If you have the same scenario then follow below steps:-
run command 'git pull'
delete branch from local repository
checkout that particular branch using "checkout as a new local branch" from
the Remote repository.
run command 'git branch -u <your_branch_name>'
run command 'git push or git push --force'
or you can try directly from step 4 first , if it does not work then follow entire steps.Hopefully it will help someone.
If you have your bitbucket account linked to jira.
(this answer will work for you, only if you have your jira account linked to bitbucket)
I was having the same problem trying to push my current branch with the origin.
for example:
my branch name was:
feature/PREFIX-000-new-name-branch.
previous commit:
git commit -m "Write your commit here"
so far it was not working.
you have to mentioned the ticket name in the commit.
if you have made the commit, make an --amend to rename your commit and retry it.
git commit --amend -m "PREFIX-000 Write your commit here"
try the push again.
If you are using BitBucket, this issue occured when I tried to push to a branch but that branch has writing disabled via the repository settings.
if you have already created a project locally and you want to upload it to git,
you will then need to do:
git status to see the changes you need to upload
git add . to add those changes to your repo
git commit -m "" to add a commit message
git push origin master
that way I solved the very same problem I
was having.
it might be a configuration issue
I fixed this issue after updating the global user.email value with my email
git config --global user.email my#email.com
Note: You need to delete the previous commit because it had the wrong email in the commit

Heroku+BItbucket deploy: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart

I am now working on a website. I use heroku to run my server and use bitbucket as the version control tool. I setup a pipeline to deploy directly from bitbucket to heroku. But I keep getting an error like:
+ git push https://heroku:$HEROKU_API_KEY#git.heroku.com/$HEROKU_APP_NAME.git HEAD
To https://heroku:57eb7889-7395-4a7e-bd95-1312a40b30d1#git.heroku.com/hidden-ocean-90048.git
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'https://heroku:57eb7889-7395-4a7e-bd95-1312a40b30d1#git.heroku.com/hidden-ocean-90048.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.
I tried git pull and git pull -f but it doesn't work. Please help me.
You can push with -f like the below:
git push -f https://heroku:$HEROKU_API_KEY#git.heroku.com/$HEROKU_APP_NAME.git HEAD

How to do push for new repository?

I created new repository (git#github.com:derkode/ForvoClient.git) and did SSH Key, then:
git config --global user.email "my_email#mail.com"
git config --global user.name "my_nickname"
git config --global push.default simple
git init
git add *
git commit -m "First commit"
git remote add origin git#github.com:derkode/ForvoClient.git
But after: git push -u origin master
! [rejected] master -> master (non-fast-forward) error: failed
to push some refs to 'git#github.com:derkode/ForvoClient.git' hint:
Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git
pull') hint: before pushing again. hint: See the 'Note about
fast-forwards' in 'git push --help' for details.
What is it?
Your repo on GitHub already has a commit.
https://github.com/derkode/ForvoClient
This is normal when you create a repo with a README file.
You can fix this either by force pushing your local repo to GitHub, but you will lose the README file this way:
git push -u origin master -f
Or, you can merge the version on GitHub into yours and then push it back:
git pull origin master
git push -u origin master
Or, as #xbonez suggested, rebase your version on top of GitHub's version:
git fetch origin
git rebase origin/master
git push -u origin master
If you want to get rid of the commit that Github created for you with the README file, follow janos's answer. If you want to keep that commit, and push yours over it, simply pull down those changes and then push:
git fetch origin && git rebase origin/master && git push origin master

Getting error when trying to git push to remote branch (Heroku)

Hi I tried to push my local changes to heroku production but I am getting the following error
Zhens-MacBook-Pro:Dailymuses-Server-Side zaikshev88$ git push heroku-production master:master
To git#heroku.com:dailymuses.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#heroku.com:dailymuses.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
The issue here is that when I tried to do a git pull, I was told that everything is up to date
Zhens-MacBook-Pro:Dailymuses-Server-Side zaikshev88$ git pull origin master
From github.com:mingyeow/Dailymuses-Server-Side
* branch master -> FETCH_HEAD
Already up-to-date.
What is the issue here and how can I resolve it?
Your push command is to remote heroku-production but your pull command is to origin. The non-fast-foward message means the history in your current repo differs from the Heroku remote; likely someone has pushed a branch with some merges or rebases.
I implore you to not use Heroku as the authoritative git remote. Assuming you are not, you can force push over the Heroku master branch to resolve this.
git push -f heroku-production master:master

Resources