Can't do a git pull or a git push

379 views Asked by At

When I do a git pull in the master branch, git show this message:

There is no tracking information for the current branch.
Please specify which branch you want to merge to.
See git-pull(1) for details.

git pull <remote> <branch>

If you want to set up the tracing information for this branch, you can do it with:
git branch --set-upstream-to=origin/<branch> master

And when I do git push in the master branch, git show this message:

fatal: The current master branch does not have an upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream origin master

So I do git push --set-upstream origin master, git show this message:

To <my-server-name>
! [rejected] master -> master (non-fast-forward)
error: failed to push some references to '<my-server-name>'.
help: Updates were rejected because the tip of your current branch is
help: behind its remote counterpart. Integrate remote changes (i.e.
help: 'git pull ...') before pushing again.
help: See 'Note about fast-forwards' in 'git push --help' for details.

Please help me!

2

There are 2 answers

0
akseli On BEST ANSWER

You first need to make sure your local branch references the upstream branch by runing: git branch --set-upstream-to=origin/<branch> master

After that, you'll want to perform git pull to fetch the missing changes from your upstream branch.

Once you have the changes, you'll be able to perform a git push, but it's also possible that you'll have to perform a manual merge in order to resolve any conflicts that arise from the changes you've made and those that were present in the upstream branch.

0
big bob little On

First of all you must point your local codebase to match a remote git branch. This can be achieved by typing this into your terminal if you haven't already . Replace '<branch' with the name of the branch in github/bitbucket etc, also known as remote. If you don't have any remote branches, it'll default to either master/main

git branch --set-upstream-to=origin/<branch> master

The second part where you can't push to master after you entered this command

git push --set-upstream origin master

is because there are changes in the remote(eg. github) which is currently not on your local machine. so you have to pull those changes, so that your local branch and remote can be up to date before pushing back to the remote branch.

You can do that with either one of the following

git pull 
git pull origin master

Another thing you might see is git prompting you on what policy it should use to further pull changes from the remote to your local machine. it could be one of

  • merge / rebase

Base on your preference, you will have to set it by entering the command that will show up along that message in your console.