I can not "push" from Git

3

I want to send my code to my remote repository but I have a problem when doing push from my Git console.

Once I have added all my income, my password https :
git remote add origin https://github.com/...
then it is necessary to do push then login:
git push origin master
but I get the following accompanied by an error:

  

To link
   ! [rejected] master - > master (fetch first)
  error: failed to push some refs to ' link ...'
  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.

tells me that I do not have it locally, so I put:
git remote --v
to see if I was targeting the remote repo (since I could not think of a solution) and I was effectively pointing to it.
It does not let me go from local to remote my code.

Does anyone know what is happening or what am I doing wrong?
I hope you can help me. Thank you very much.

    
asked by BrandCodes 14.12.2017 в 05:45
source

3 answers

3

As the error message tells you, this happens in general because the code you have locally in your repository differs from the code that is in the remote repository. First you have to update your local repository to contemplate the changes ( commits ) that have occurred in the remote, fix the conflicts and then allow you to upload the code.

A couple of notes to older:

  • If you have downloaded the repo with a git clone it should not be necessary to do a git remote add by hand it should already be configured.
  • The git remote add is usually used when you create a local git repository in which you are adding 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 case, initial should never give you problems to do the push
  • On very rare occasions you may be interested in "overwriting" the remote changes directly with what is in your local repo. If you are not very sure what this is worth and why you need it, you should not do it. In any case, the command would be git push -f referencia_remota referencia_local
  • One of the possible ways to work in git, to avoid problems would be following this flow:
  • I release the repo with git clone
  • I create a local branch where I work git checkout -b mi_rama_local and I'm adding commits to that branch, until the feature or bug is resolved.
  • You go to master with git checkout master and you bring the possible changes that are in remote git pull
  • Go to the local branch with git checkout mi_rama_local and integrate the new master changes with git rebase master into it. This would put the changes in master below your current changes to say it in some way. This avoids empty merge commits. Some teams like to have those commits to know when they integrate and others do not. They particularly bother me. that's why I do it like that.
  • If there is a conflict, you solve it
  • You change to master and you bring the changes of the local branch git merge mi_rama_local
  • You upload the changes git push origin master

If you have been working directly on master, what some people consider a bad practice, you can try to bring the remote changes directly below your local changes with git pull --rebase , resolve conflicts and make git push

    
answered by 14.12.2017 / 11:15
source
3

Before doing git push always but you should always do git pull , if in case there is a conflict you must fix them manually, and those files that have conflict you must add them again.

    
answered by 14.12.2017 в 05:51
3

You simply need to pull before pushing, in case there is a conflict, correct it before uploading your thing.

Methodology when you start git.

  • Git status - > See if you have modifications of yours and if there is a pull or push
  • Git fetch - > In case your branches have not been updated correctly, this does NOT update the files of the branches, only the state of that branch
  • Git status - > To check again modifications, pull and pushs
  • Git pull - > Now you do download the updates
  • Git add / commit / ... - > Now save your modifications
  • Git status - > See that you still do not need a pull, just in case the flies
  • Git push - > Upload your data
  • Git status - > You check that everything is correct

And because of mania you can do one:

  • Git log - > To verify that what you have been commissioned is correctly pusheado

To exit Git log, press "Q"

As time goes by, you'll get used to it

    
answered by 14.12.2017 в 11:57