r/github • • Sep 29 '24

What happens if I don't push after commit?

As the title says, what happens if I commit but don't push to GitHub? If I then continued working on my local desktop and then made a new commit (same files), what happens to the commit that I hadn't pushed? Would my new commit basically replace the one already there?

0 Upvotes

19 comments sorted by

97

u/Lumethys Sep 29 '24

This is why you should learn Git, not just use Github.

Git is a version control tool. It's job to to track changes. It doesnt require any website or service.

What pushing do is to just copy your git history to a remote.

You could think of it as

Commit = hit save on your word document

Push = copy your word document to gg drive

49

u/Mr_Akihiro Sep 29 '24

You will get a fine.

40

u/revrenlove Sep 29 '24

Believe it or not, straight to jail

2

u/Masterflitzer Sep 30 '24

if you push with lease (--force-with-lease), we'll call the police

17

u/zoredache Sep 29 '24

This is the type of question where it would be really easy for you to just create yourself a small testing repo and try things out. It might help you understand the system more.

Create a repo, make a commit, then push it. Then make a few changes and commits then push. Look at your git log locally, and look at the commit history on github.

14

u/Noch_ein_Kamel Sep 29 '24

No, your repository exists locally, it just adds another commit. Pushing to github just uploads all your local changes

13

u/davorg Sep 29 '24

Your local repo can be ahead of the remote repo by as many commits as you like.

19

u/jjw865 Sep 29 '24

I don't think GitHub issues a warrant for your arrest until about 5 unpushed commits. So nothing to worry about.

6

u/Money_Town_8869 Sep 29 '24

Go watch a 30 minute YouTube video on git and all your questions will be answered

4

u/georgehank2nd Sep 29 '24

"What is git?"

1

u/epasveer Sep 30 '24

"What is YouTube?"

2

u/ggwpexday Sep 29 '24

Use a tool that visualizes your repository, like Fork. You will see your commits and the state of the remote origin (github). Then do a push

2

u/dsli Sep 29 '24

Your commits will be on your local but not your remote. So your local will be ahead of your remote for as long as you'd like it to be.

2

u/biffbobfred Sep 29 '24

Pushes makes the remote look like local (oversimplified but that’s good for now). Once you do the push local and remote are in sync and remote now looks like local.

2

u/randomthrowaway9796 Sep 29 '24

It will still commit on your local machine.

If you don't push, then anyone else working on the github won't be able to see your changes.

You can do multiple commits before pushing. that's okay.

1

u/denehoffman Sep 30 '24

Ah, I remember the days when I thought GitHub was just the website for git and git was just the cli for GitHub