Remote GitStack - Create Branch

877 Views Asked by At

I just can't understand why such an easy looking stuff is not written anywhere... So I'm struggling to create a branch on a remote GitStack repository. I've looked over dozens of web pages and found countless recommendations, but any of those I'm trying, I always end up with the "fatal: not a git repository (or any of the parent directories): .git" error message. I created an empty repository in GitStack using the web interface. So far my best try was:

git clone http://abc.def.ghi.jkl:9876/TestRepo.git

This told me that I've cloned an empty repository. Then I've tried to push a branch:

git push remote http://abc.def.ghi.jkl:9876/TestRepo.git

And for this I received the error message every single time. So the basic problem: I can't push my project to the Git repo because there exists no branch. But I can't even create a breanch. Any constructive idea where I went wrong?

3

There are 3 best solutions below

0
On

You first have to commit changes locally before you can push them.

git add .
git commit -m "Commit message"
2
On

Intially you have an empty local repository.

Add some files to the folder and run these commands

git add *
git commit -m 'My message'

If you are looking for a branch do the following.

git checkout -b branchName

This creates a branch and automatically moves you to it. Add some files or change some files and do the same as first time so:

git add *
git commit -m 'My message'

Now you have a commit in the master branch and a branch called branchName branching from the first commit. Now you can stay in your new branch and keep working there or you can switch back and forth between master and your branch to do work in both places.

git checkout master - takes you back to master
git checkout branchName - takes you to the branch

If you want to merge you branch to master do the following:

git checkout master
git merge branchName

Then fix the conflicts if any araise and continue with

git add *
git commit -m 'Commit message'

Hope I clarified it for you

If you want to use git push to push a branch then simply do this

git push origin branchName:remoteBranchName

branchName is the name of the branch you want to push and remoteBranchName is the name you want it to have when you push it to the server.

Origin is the default name given to the remote repo when you first time clone. If origin doesn't exist or your remote has a different name then run this:

git remote - this will list all remotes set up

Then just use one of the names from the list (whatever one you want to push to)

0
On
git push remote http://abc.def.ghi.jkl:9876/TestRepo.git

This means, that you want to push the branch http://abc.def.ghi.jkl:9876/TestRepo.git to the remote named remote. What you are looking for is

git push origin <localBranchName>[:<remoteBranchName>]

origin is the default name for the remote you initially cloned from. You can changed it in whatever your want (as well as you can have as many remotes associated with your local repository), but thats another topic.

localBranchName is the name of a branch in your local (workspace) repository. Of course it must exists

git branch localBranchName
git checkout localBranchName

And usually you should have something useful comitted to it

# do something useful
git add fileA
# and so on (or just "git add .")
git commit 

Now you can push it

git push origin localBranchName

You can omit the remoteBranchName if it should be the same as the local name. Btw: The(by convention) default branch name for the primary development branch is master (compare with SVNs trunk)

Update: Something to read :) http://git-scm.com/book