I\'m new to GitHub. Today I met some issue when I was trying to push my code to GitHub.
Pushing to git@github.com:519ebayproject/519ebayproject.git
To git@gi
git pull origin branch_name --rebase
This worked for me -- the command git pull origin branch_name --rebase
will pull changes from remote branch_name at first, then rebase
current branch on the top of it.
In addition to the answers above, the following worked for me : -
Scenario -
Solution -
1. git checkout **my_branch**
2. git add, commit your changes.
3. git pull origin **my_branch** (not origin, master, or develop)
4. git push origin **my_branch**
This problem is usually caused by creating a readme.md file, which is counted as a commit, is not synchronized locally on the system, and is lacking behind the head, hence, it shows a git pull request. You can try avoiding the readme file and then try to commit. It worked in my case.
This can cause the remote repository to lose commits; use it with care.
If you do not wish to merge the remote branch into your local branch (see differences with git diff), and want to do a force push, use the push command with -f
git push -f origin <branch>
where origin
is the name of your remote repo.
Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care.
The problem with push command is that you your local and remote repository doesn't match. IF you initialize readme by default when creating new repository from git hub, then, master branch is automatically created. However, when you try to push that has no any branch. you cannot push... So, the best practice is to create repo without default readme initialization.
Some of you may be getting this error because Git doesn't know which branch you're trying to push.
If your error message also includes
error: failed to push some refs to 'git@github.com:jkubicek/my_proj.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.
then you may want to follow the handy tips from Jim Kubicek, Configure Git to Only Push Current Branch, to set the default branch to current.
git config --global push.default current