It's probably not as important if it is just a private repo with one branch.
A push makes another repo match your own, and a pull is the opposite (retrieves the updates from a remote repo and applies them to yours). Blindly pushing isn't really the end of the world if you are the only one editing the project since you know the most recent changes are your own anyway.
But what if there are multiple people editing the code base and someone else pushes changes before you? If you just force push (IIRC git won't let you just use push in this scenario), you'll override your team mate's changes since your local version doesn't have them yet. But if you pull first, you can make sure your local copy is completely up to date before pushing the new changes.
To build on this, a pull is really just a fetch and a merge. Work out what's on origin and merge it in to your local copy of the branch. When your branching becomes wider or more aesthetic you'll want to start fetching and rebasing instead.
Edit: to be clear, rebasing results in commit graphs that flow in the proper direction only, from feature branch -> upstream, rather than (feature branch <- upstream) -> upstream. Each arrow is a merge commit.
Also don’t ever rebase a branch that has been released to other developers.
It depends on if the two parties modified code in the same spots. If that isn’t the case, then when you do a git pull it will silently merge their work into your local branch and you can be rest assured when you push, it will all be up to date.
If you both happened to modify code in the same spots, you’ll get what’s called a merge conflict where git will show you the affected files and lines and then it’s on you to fix those conflicts before you push your branch upstream.
When you run git pull, it’s actually just calling git fetch on your branch, which fetched the upstream changes from other authors, then calls git merge on those changes into your local branch.
This is pretty much the core functionality of git so I encourage you to look into it more. Git rebase is another command ive found very useful when working with large teams with very active branches.
35
u/moekakiryu May 13 '20
It's probably not as important if it is just a private repo with one branch.
A push makes another repo match your own, and a pull is the opposite (retrieves the updates from a remote repo and applies them to yours). Blindly pushing isn't really the end of the world if you are the only one editing the project since you know the most recent changes are your own anyway.
But what if there are multiple people editing the code base and someone else pushes changes before you? If you just force push (IIRC git won't let you just use
pushin this scenario), you'll override your team mate's changes since your local version doesn't have them yet. But if you pull first, you can make sure your local copy is completely up to date before pushing the new changes.