Reputation: 1315
I am finally starting to understand the fundamentals of git, but I just want to make sure I understand this particular part of it.
I've been using the git functionality inside Visual Studio, so I've been accustomed to the "sync" button. Ugh. Now I am doing everything from the command line, however I just want to be certain that when I push up to origin master I am doing things correctly. I am the only developer working in the remote so this is a low risk situation (relatively speaking).... but should I always at least git fetch before I push? Seems like I should have to to ensure I push into a remote repo that my local repo is update to date with. Right? What would happen if I pushed and remote / local were out of sync? Do I get an error?
Upvotes: 1
Views: 2261
Reputation: 6657
You don't have to pull/fetch every time before you push. If your push conflicts with what is already in the remote repository, git will give you an error, like this:
$ git push
To [email protected]:your/repository.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:your/repository.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.
Upvotes: 2