I want to send my code to my remote repository but I have a problem when pushing from my Git console .
Once I have everything added, I enter my https key :
git remote add origin https://github.com/...
later it is necessary to push , so I enter:
git push origin master
but I get the following accompanied by an error:
To https://github.com/myUser/myRepo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ' https://github.com/ ...'
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: (eg, 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
It tells me that I don't have it locally, so I put:
git remote --v
to see if it was pointing to the remote repo (since I couldn't think of any solution) and indeed it was pointing to it.
It won't let me pass my code from local to remote .
Does anyone know what's going on or what I'm doing wrong?
I hope you can help me. Thank you so much.
As the error message tells you, this usually happens because the code you have locally in your repository differs from the code in the remote repository. First you have to update your local repository to take into account the changes (
commits
) that have occurred in the remote one, fix the conflicts and then it will allow you to upload the code.A couple of major points:
git clone
it should not be necessary to do agit remote add
manually it should already be configured.git remote add
is often used when creating a local git repository where you add changes. Next you create a remote empty repository on GitHub or any other server. And you want to upload your local code to the remote repo. In this initial case you should never have any problems doing thepush
git push -f referencia_remota referencia_local
git clone
git checkout -b mi_rama_local
I work on and add commits to that branch until the feature or bug is resolved.master
withgit checkout master
and you bring the possible changes that there are in remotegit pull
git checkout mi_rama_local
and integrate the new master changes withgit rebase master
. This would put the changes in master below your current changes so to speak. This prevents empty "merge" commits. Some teams like to have those commits to know when it was integrated and others don't. I find them particularly annoying. that's why I do it like this.git merge mi_rama_local
git push origin master
If you've been working on master directly, which some people consider bad practice, you can try bringing your remote changes directly below your local changes with
git pull --rebase
, resolve the conflicts, and dogit push
You just need to pull before you push, in case there is a conflict correct it before you push yours.
Methodology when you start git.
And now for hobby you can do a:
To exit Git log, press "Q"
As time goes by you will get used to it.
Before doing
git push
always but you should always dogit pull
, if in case there is any conflict you must fix them manually, and those files that have conflict you must add them again.