Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

Kip Brown
Kip Brown
590 Points

Git - Pushing from a remote git master branch to the master (and checked out) branch in the origin git.

I am trying to test how a remote git repository that sits on my own computer would work before I move to setting up one on my work network. When I clone a remote git and then try to make a change on the master branch of the remote git and push it back to the master branch of the origin git I get this error message:

[remote rejected] master -> master (branch is currently checked out)

I learned that one can clone a bare git repository with the --bare option, and it works, but it seems like a workaround.

Does this mean one should always send updated work to the central remote repository as a branch to be safe, or just that we always need to manually go into the central repository and checkout a dummy branch if we want to push to the master branch directly?

What are the best practices here? I think the fact that Tommy pushed a different branch in the video avoided this problem.

Thanks!

Kip

2 Answers

Either you or I are getting a little confused... A remote refers to a repository that is not on your local machine/server, that you are interacting with. Origin is simply a name given to the remote that you originally cloned the repository from. So be default, if you run the following command, it will try to push back to master branch of the remote repository you cloned from:

git push origin master

Depending on the repository/project, you might be expected to push to branches on the remote/origin and/or submit pull requests (or do a regular git merge if PRs aren't available).

Here's some documentation on remotes:

Kip Brown
Kip Brown
590 Points

I was/am definitely confused, but I think I got a little clarity on it. Basically, I'm trying to set up a little self-contained git system at work all within one folder (because the data/code is confidential) on a mapped server drive. So, I ended up initiating a central repository via git init with the --bare option, and then cloned this as needed. After a bit more reading, I realized the --bare option is actually the right way to go for a central repository (might not be using best terminology here). The single folder setup definitely isn't ideal, but at least we get the major organizational benefits of git.

You could also look at running an internal instance of Gitlab, which is basically like self-hosted GitHub. That way you get a nice user interface, central user management, and APIs/hooks to use if desired.