Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to commit my changes before pulling in Git?

Tags:

git

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?

like image 204
user2896521 Avatar asked Jun 26 '14 18:06

user2896521


People also ask

Can I git pull with uncommitted changes?

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.

Does git pull make a new commit?

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.

Is a pull request a 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.

Do I need to push before pull request?

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.


2 Answers

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.

like image 69
gravetii Avatar answered Oct 11 '22 17:10

gravetii


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.

like image 41
davidicus Avatar answered Oct 11 '22 16:10

davidicus