Skip to content
Donald Buczek edited this page Nov 23, 2016 · 10 revisions

mariux64/bee-files Cheatbook / HOWTO and FAQ

Create a new "feature branch" for a pull request

git checkout master
git pull                      # make sure, you are branching from the latest and greatest version
git checkout -b add-foobar

Rename a feature branch

git branch -m add-foobar add-barfoo

Push your feature branch to github.molgen.mpg.de

git checkout add-foobar       # be on you branch
git push                      # and push it

If you are doing this for the first time, git will not yet know, where to put the branch. But (as often) it has a good suggestion in the reply:

fatal: The current branch add-foobar has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream origin add-foobar

so in that case, do as you are told:

git push --set-upstream origin add-foobar

github rejects my push

! [rejected] add-foobar -> add-foobar (non-fast-forward) error: failed to push some refs to 'git@github.molgen.mpg.de:mariux64/bee-files.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

You are welcome to force-push your own feature branch even if a pull request is open.

git push -f

I want to change my commits

If you are not happy with you commits, perhaps because someone suggested an improvement and you want to fix spelling errors, split one commit into two, remove a commit, and tidy up everything, the magic feature is git rebase -i

git checkout master
git pull                       # get the latest master
git checkout add-foobar        # go to your branch
git rebase -i master           # re-apply your changes on top of the current master. -i lets you edit them

Now you are in your editor where you can give orders, what to do with each commit. The template includes some help text.

During a rebase or merge I've got confused and just want to get out and start over.

git rebase --abort git merge --abort

Oops - I've accidentally committed on the master

git branch add-foobar       # create the feature branch. Now add-foobar and master are equal
git reset origin/master     # reset your branch "master" back
git checkout -f add-foobar  # switch to your feature branch

Why the "-f" here? Typically you've added or changed some files. When we git reset origin/master we only let our "master" branch point to another commit. We did not change the work directory and the files you've added or modified are still there. git status shows it.

Not if you checkout add-foobar which contains commits for the new and changed files, the checkout would overwrite the files in you working directory which are not already committed to the master branch. (Why doesn't git detect, these have the same contents?). The "-f" says we are happy to overwrite these files.