I can never seem to figure out how to use git. I just do random commands and it works eventually. This is what I usually do when I want to push:
-
Fetch from upstream
-
Commit
-
Push to upstream
However, the above steps don’t work sometimes. For example, when I do fetch from upstream, my local branch doesn’t get updated.
How do I merge the remote branch into my local branch? Is there a difference between pull and fetch?
“git pull” is equivalent to “git fetch” followed by “git merge”
What you want to do is:
This commits your current changes locally, and only locally. Now, assuming branch “foo”:
This does a “git fetch” followed by a “git merge”. Everything in this step is done to your local branch, and still has no effect on the remote branch. Depending on how your git is setup, you might need to specify the branch.
If you have a merge conflict, you will have to fix the files listed, then add them back:
When you are done, push everything you have from your local changes, to the remote server:
If you pull before committing, that might cause your local branch to not be updated.
tl;dr, always commit before pulling!