My git notes

Disclaimer: Once agian this page is probably just a mishmash of my random thoughts, and will most likely get you into trouble.

A better workflow

  • Bare repo on Sarah in accessible location over ssh
  • master and dev branches are tracked
  • other branches could be pushed manually to the repo.

Need to read the git book again really! Keep testing.

A possible workflow (for websites)

  • Even small bug fixes etc.. should be made in their own branches. Randal Schwartz does this anyway.
  • New features/additions occur in their own branches
  • Crazy ideas and fun stuff can be sub-branches of these unique feature branches etc..branches good.
  • Master branch is considered live, no changes other than real-time bug fixes and merges to be made here
  • Look into tracking branches. Perhaps we make master our tracking branch?
  • You can rebase your local commits and squash before doing a push to consolidate them into more niceness.

Level 2 Headline

Un-tracked and un-commited CHANGES (new file, deleted file, whatever) will always appear in your working dir (they are in the index, the index isn't anything to do with branches.) The changes you have made will be commited to the current branch when you commit

Initialize a new git repo

init

Add a new or changed file to the index, staging it for the next commit. You don't have to add files, you can leave them out until you're ready to have them tracked.

add somefile (or wildcard, . or what not)

Add everything and commit in this branch

commit -a

Create a new branch

branch mybranchname

Switch to a different branch (! You can't switch unless changes are commited or stashed in the current branch)

checkout mybranchname

Stash your changes on current branch to avoid having to commit them (or having them merged.) Note that stashing will remove (until unstashed) all your changes since the last commit of the branch:

stash

Un-stash:

stash apply

List stashes:

stash list

See what branch we're on

branch

Merge changes from mybranchname to current branch (! if they're commited from mybranchname they'll be commited in current branch)

merge mybranchname

Questions:

  1. Why are unstaged un-checked out modifcations being merged when we switch branches?
john@workvm:~/git-test$ git init
Initialized empty Git repository in /home/john/git-test/.git/
john@workvm:~/git-test$ ls
afile  a.out  hello.c
john@workvm:~/git-test$ git add .
john@workvm:~/git-test$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file: a.out
#       new file: afile
#       new file: hello.c
#
john@workvm:~/git-test$ git commit -m "Git test project"
Created initial commit afa7dff: Git test project
 3 files changed, 12 insertions(+), 0 deletions(-)
 create mode 100755 a.out
 create mode 100644 afile
 create mode 100644 hello.c
john@workvm:~/git-test$ git status
# On branch master
nothing to commit (working directory clean)
john@workvm:~/git-test$ git branch development
john@workvm:~/git-test$ git status
# On branch master
nothing to commit (working directory clean)
john@workvm:~/git-test$ git branch
  development
* master
john@workvm:~/git-test$ git checkout development
Switched to branch "development"
 
horrible_guide_to_git.txt · Last modified: 2010/02/19 05:59 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki