It looks like I'm missing basic understanding of git pull
and git commit
, let's say I'm working on branch and it was updated by other developer while I was doing my job locally. Should I commit changes before issuing git pull
or should I do git pull
and then do git commit
?
When your uncommitted changes are significant to you, there are two options. You can commit them and then perform git pull , or you can stash them.
In the first stage of operation git pull will execute a git fetch scoped to the local branch that HEAD is pointed at. Once the content is downloaded, git pull will enter a merge workflow. A new merge commit will be-created and HEAD updated to point at the new commit.
A pull request is a way to 'commit' to a repository in which you don't have writing permissions. The maintainers of that repository will check your request and decide if they either want to merge it with your code or leave the original as it is.
Always Pull Before a Push This is a bedrock rule. Before you try to push code out to the repository, you should always pull all the current changes from the remote repository to your local machine. Doing so will ensure that your local copy is in sync with the remote repository.
You can do a commit anytime you want - all your commits are local.
It's only when you need to push
to the server that you need to have its latest copy. So it's a good idea that you always pull
from the remote repository before you push
your changes.
So, I think what you mean is "Should I push changes before issuing git pull or should I do git pull and then do git push". You should ideally pull
before you push
which adheres to the basic idea of adding code to the most recent copy of the public repository.
You might be notified of some merge conflicts obtained by merging the public repository, which you need to resolve before you can finally push your changes.
If you have uncommitted changes to existing files in your branch git won't let you pull. You can either commit what you have, or use the --autostash
flag when pulling and then you'll be able to pull.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With