1

how come running git branch branchname the branch does not appear on the github website and why cant i push to a branch that i made locally. I have done this:

git clone https://github.com/myname/myrep.git 
git branch gitcheat
git checkout  gitcheat
git branch

* gitcheat
  master

i tried

git push gitcheat gitcheat

but i got

fatal: 'gitcheat' does not appear to be a git repository

How do i get my local branch to be stored online in the git repo as a branch so i can push and pull to it like i do with the master branch

Dr Manhattan
  • 13,537
  • 6
  • 45
  • 41

1 Answers1

2

You need:

git push -u origin gitcheat

origin is the name of your upstream repo url: https://github.com/myname/myrep.git

I prefer adding myname in the server part, in order to only have to enter my password when pushing back:

git remote set-url origin https://myname@github.com/myname/myrep.git 

That will be for the first push only: after, a simple git push will be enough, see "Why do I need to explicitly push a new branch?".

Make sure your push.default policy is set properly:

git config --global push.default simple
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • when i delete my local branch the one on github website remains intact, do i have to delete it manually always or is there a better way. also what does the -u do in the push command – Dr Manhattan Dec 29 '14 at 10:49
  • 1
    the -u (illustrated in http://stackoverflow.com/a/17096880/6309) does set an upstream branch (meaning your local branch knows where to push to: `origin/gitcheat`. It tracks it: see http://stackoverflow.com/a/6244487/6309). And yes, deleting a branch is a local operation: you need to push that deletion: see http://stackoverflow.com/a/2003515/6309: `git push origin --delete gitcheat` – VonC Dec 29 '14 at 11:09