0

I've been asked to work with a Github repository and the only Git related procedure I've ever done is cloning an existing repository. I've worked with SVN alot but I'm a bit of a noob when it comes to Git branches and working trees. The docs are a little abstract and don't really outline what best practices are regarding creating new branches and committing changes.

I'd like to clone the existing repo to a new branch that is available to all that have access to the master branch (SSH), then work locally off the newly created branch and commit changes to that branch only. From online docs and guides, the general consensus seems to be:

  1. Clone repo which creates a remote named origin
  2. Create a new local branch off master
  3. Commit changes to local branch

My question is how will the local branch be available on Github to others with access to the repo? What's the general procedure for cloning a repo and creating a new branch available remotely? Any suggestions at all would be much appreciated.

1
  • 1
    Maybe I'm missing something, but you know you can git push origin <localbranch>?
    – slhck
    May 30, 2013 at 6:40

2 Answers 2

1

The local branch will not be available to others who have access to the github repo until you push your branch and commits back to the master using "git push".

As an example, say I want to download the existing "my-project" repository at "some-site" with ssh access where the only existing branch is the master branch. Then I'll add a "new-feature" branch and push the changes back to the originating repository, I would do the following:

  1. git clone ssh://some-site/my-project.git
  2. git branch new-feature
  3. git checkout new-feature
  4. < make some changes, add files, remove files, etc >
  5. git commit
  6. git push origin new-feature:new-feature

what each command is doing:

  1. clones the remote repository to your machine
  2. creates a new-feature branch in the local repository
  3. changes the working branch to new-feature
  4. self explanatory
  5. commits changes made in step 4 to the local repository (nothing changes on the remote repo)
  6. pushes the local new-feature branch to the new-feature branch on the original repo

At this point, anyone who has access to the originating repository will have access to the new-feature branch. When someone else clones the repo or syncs their local repo with this origin the new-feature will appear when they run the "git branch" command.

1

You should read the Git Pro book, the answer to your question is in the first chapters.

None of your commits will be available for others unless you push it. When you want to publish that branch's current state, you do git push origin <branchname>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.