Git - Pushing Local To Remote

Hi, I’ve been practicing using git and trying to figure it out. If I create a local branch and finish a feature, would I merge that branch back into my local main branch and then push the local main branch to the remote? Or would I push the new branch to the remote and only update my local main from the remote? Thanks

Hey Jax!

This depends on what you are doing, and how you are managing your repository. You need not even keep a remote repository if your project doesn’t need it!.

So if you would like to keep your online repository in sync, you would follow this process.

secondary branch → (merge to remote secondary branch) → PR to merge remote secondary branch to remote main branch → (merge them) → sync local main branch with remote main branch.

But this is only if you would like to keep a remote repository in sync. You may also choose to only keep the main branch in sync, or some other branch depending on what your goal is.

Hope this helps

1 Like

Hey! So to start out would I create the secondary branch on GitHub or locally?
I’m just trying to get familiar with how it would be to work on a project with other people, so I’ll be familiar with everything when I get to that point. So whatever would be the most common way of doing it is what I’m aiming for. Thanks!

Either way works.

The way I prefer is to create the remote repository first. But I’ve seen developers do the other way round as well.

I find it easier to just create the repository online and sync it locally.

1 Like

You don’t have to worry about how it works with multiple people as of yet. When you are working on a project with multiple developers, they always explain the process they follow to you.

And if you are looking to contribute to open source work, there’s always a readme that outlines how to contribute to that specific project

1 Like

Ok. Good to know. I think I’ll keep tinkering with it since I’m just curious how it all works, but I won’t worry about it if I’m not a pro by that time. I figured out one thing I was doing wrong; I was trying to push the new branch to the remote main branch. I found out I had to push to the new branch name instead, and got it to work. Really appreciate your time. Thanks for the help!