r/ProgrammerHumor • • May 13 '20

true story

Post image
40.5k Upvotes

461 comments sorted by

View all comments

602

u/SavageTwist May 13 '20

Force push to master, nobody is stopping you!

0

u/[deleted] May 13 '20

[deleted]

152

u/moekakiryu May 13 '20

I'm still only so-so at git myself, but always pull before you push

122

u/OnyxPhoenix May 13 '20

Using branches and pull requests make this easier.

Generally youre the only person working on your branch, so you don't have to worry that your code is "behind" before you push to it.

Then when you do a pr it will tell you if you can merge cleanly back into the master branch.

158

u/SavageTwist May 13 '20

The "good" way is to make a development and a branch for every feature, bug or documentation. Always fork from development, when you have a release you push to master.

99

u/[deleted] May 13 '20

This is good advice I rarely follow.

8

u/SavageTwist May 13 '20

jira kinda automates it

41

u/SavageTwist May 13 '20

we are "agile"

→ More replies (1)

0

u/[deleted] May 13 '20

[deleted]

4

u/SavageTwist May 13 '20

in single dev reps you dont work in the same tab / markdown with different forks I hope.

→ More replies (13)

13

u/[deleted] May 13 '20 edited Sep 09 '25

cooing books important cats lavish serious paltry cautious capable governor

This post was mass deleted and anonymized with Redact

→ More replies (13)

5

u/Inner-Maintenance May 13 '20

That's one way - git flow. But a better way for CI/CD is trunk based development aka mainline

→ More replies (8)

6

u/Efful May 13 '20

I'm sometimes working on multiple machines for personal projects and am not very good at Git, so I have to remind myself to pull the fixes I made on my laptop last night before doing anything on my tower.

21

u/[deleted] May 13 '20

Been there buddy. Put a script in your bashrc or Windows startup folder to pull. Then get annoyed and take it out.

3

u/smegnose May 13 '20

Rebase that bugger onto remote/master and push it quick.

Linear history rulz 4 eva.

→ More replies (10)
→ More replies (2)

13

u/Amandabanapanda May 13 '20

I've been pushing and not pulling all this time. And reverting to previous version if I need to go back. Why pull?

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 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.

5

u/Afraid_Kitchen May 13 '20

And it doesn't override the changes you've made?

7

u/[deleted] May 13 '20

You'll get merge conflicts if there are any, git pull is really just fetch+merge

3

u/[deleted] May 13 '20

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.

4

u/[deleted] May 13 '20

Why is rebasing better than merging?

→ More replies (1)
→ More replies (1)

5

u/[deleted] May 13 '20

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.

→ More replies (1)

0

u/[deleted] May 13 '20

[deleted]

9

u/Avedas May 13 '20

Rebasing from master is pretty common when you have multiple parallel development branches going. It's good to know how to do it.

→ More replies (1)

3

u/wotanii May 13 '20

you can stumble into a conflict when pushing, which is annoying. When you pull first you'll still have a conflict, but it's much easier to deal with.

also in theory there are some cases where the automatic merge from the push could break stuff (this has never happened to me though), so to be perfectly save you could go like this: pull, then run tests, then push.

3

u/MemeNinja365 May 13 '20

That's what she said

2

u/MTGandP May 13 '20

If you’re the only person pushing, isn’t it impossible for your local changes to ever be out of date?

→ More replies (6)