git push not working on a bitbucket repository - bitbucket

I've just created a repository on my Bitbucket account. I have a code already written in my laptop.
Here's the command I executed on my terminal:
git init
git add --all
git commit -m 'Initial commit'
git remote add origin https://<repo_owner_name>#bitbucket.org/<teamname>/<reponame>.git
git push origin master
I got the following error:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://bitbucket.org/EtienneVergne/disney-app-proposal.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.
I've tried several git pull as suggested in the message with no sucess.
Can somebody help me ?

It's because the remote repo and your local repo are not in sync.
See what the error logs hints
Do this:
git pull origin master
git push origin master
or
git push -f origin master to override remote changes.

Related

git push origin master shows eveything up-to-date but nothing is pushed

When I build new text file in bitbucket and pull it to my local file, it works. But when I build new text file in local and push it ot bitbucket with git push origin master,it shows everything up-to-date but nothing is pushed in bitbucket.
use these commands sequentially
1) git add --all
2) git commit -m "message"
3) git pull origin master
4) git push origin master

created bitbucket repo deleted it, created again, git remote push fails

I am using cloud9 IDE on a rails tutorial app. I created a repo and then pushed the app to the repo on bitbucket. I got messed up on the app so decided to start from beginning. I deleted the repo and worked on the app until it worked. I created another repo on bitbucket and did all commits and when I did these I got a message saying I was three or five commits ahead of remote. So when I did a push I got
git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
Everything up-to-date
If you don't mind starting from scratch and losing your app's history.
Create a new repo on Bitbucket.
Next, remove the .git directory from your local project.
Then initialize a new git repo locally
git init
git add --all
git commit -m "Initial commit"
On Bitbucket you'll see a screen like the one below.
Now just run the commands as exactly as it instructs
cd /path/to/my/repo
git remote add origin git#bitbucket.org:your-username/project.git
git push -u origin --all
git push -u origin --tags
Then everything should be reset without any history.

Heroku: ! [rejected] master -> master (non-fast-forward)

I get and error whenever I try to push rails app to heroku. What do I do to fix this? I did git init, git add ., git commit -m "complete", and git push heroku master
To https://git.heroku.com/shuabe.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/james.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.
Someone has committed so you have to update your brach width git pull in order to be up to date.
git fetch --all --prune
git pull origin master
Fetch will update all your branches & pull will grab the latest content into your master branch.
If you would read the error it explaining you what to do.
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes
More detailed
You are trying to push to a remote branch which has some commits that you don't have them locally in your branch. In order to push to a non-fast-forward repository you branch must have the latest updates from the remote repository.
How to grab latest updates?
git fetch --all --prune
This command will grab all the content of the whole remote repository and will update the internal git storage (pack & index files) inside the .git folder.
git pull origin master
This command will fetch & merge the remote branch into your local branch (master) and after that you will be able to push your changes.
And also you can use force argument.
git push --force heroku yourbranch:master
I fixed by:
git pull heroku master
After that, console shows:
From https://git.heroku.com/myweb
* branch master -> FETCH_HEAD
Auto-merging views/layout.hbs
CONFLICT (content): Merge conflict in views/layout.hbs
Auto-merging views/ads/list.hbs
Auto-merging controllers/users.controller.js
CONFLICT (content): Merge conflict in controllers/users.controller.js
Auto-merging config/db.config.js
CONFLICT (content): Merge conflict in config/db.config.js
Automatic merge failed; fix conflicts and then commit the result.
I accepted every change, and after that:
git push heroku master
git pull heroku main
Then
git push heroku main
The above commands worked for the question.
Then I got another error: your account has reached its concurrent builds limit (pre-recieve hook declined).
I resolved that with:
heroku restart
PS: git pull heroku main then git push heroku main should work straight up for heroku accounts that haven't reached builds limit.

Issue trying to push to git repository

Problem when pushing app to github. This is what I entered into the command line. Hopefully it's just a small problem I can fix thanks.
git init
git add README.md
git commit -m "first commit"
git remote add origin git#github.com:travi5567/first_app.git
git push -u origin master
This is the error I get:
Traviss-MacBook-Pro:sample_app Travis$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
If you don't know how to use SSH keys or would rather not you can also use the https remote like so:
git remote add origin https://travis5567#github.com/travis5567/first_app.git
git push origin master
Password for travis5567: <enter your password>
# regular output from a git push
GitHub uses SSH keys to configure access to git repositories. If you are the owner you can push to the repo but you need to tell git your SSH key so they know who you are first.
It's all explained on the GitHub website - https://help.github.com/articles/generating-ssh-keys

How to push existing source code to a repository in github?

I have a rails app hosted on heroku and i want to push the code to github(Aready created a repo on there).I tried to follow the steps in this question .Since i already have a local repository and currently can push and pull from heroku i skipped step 2 and 3 .But when i do step 4
git remote add origin git#github.com:sparkz19/stark-journey-1727.git
It says
fatal: remote origin already exists.
And when i do git remote -v
It says
origin git#heroku.com:stark-journey-1727.git (fetch)
origin git#heroku.com:stark-journey-1727.git (push)
What do i need to do here?Thank you in advance.
Git complains because origin is already defined. If you still want to keep the heroku remote you could use git remote rename to save it as another remote:
git remote rename origin heroku
Reset the url with git remote set-url:
git remote set-url origin git#github.com:sparkz19/stark-journey-1727.git
Now you can push and pull to any you like:
git pull heroku master
git push origin master
Just give your new remote a different name than origin and you'll be good to go.

Resources