GIT
Contents
- 1 Vital Facts
- 2 Preconceptions
- 3 Using git
- 3.1 Register Yourself
- 3.2 Have GIT manage your existing code
- 3.3 Check the status of your code
- 3.4 Add files to be managed by GIT
- 3.5 Commit your changes
- 3.6 See the history
- 3.7 List branches
- 3.8 Create a branch
- 3.9 Switch to a branch
- 3.10 See what's on another branch
- 3.11 Merge changes from another branch to this one
- 3.12 Start a project from someone else's project
- 3.13 Pull in changes form another project
- 3.14 Using a remote repository
- 3.15 Pulling in changes from a remote repo
- 3.16 You've Got Some Great Code But You Can't Commit
- 4 Creating a Release
Vital Facts
GIT is included in Fedora as "git".
http://book.git-scm.com/index.html : Community book.
Graphical explanation of what Git is doing
Preconceptions
GIT seems to be nice. I think I understand how it works, and it is reasonable.
I like the idea that it was designed with the user, not the implementor, in mind.
I like how you can create repositories on the fly. Heck, I have tens of SVN repositories on my machine at home.
I like how branching and mergine aren't really that big of a deal.
I like how you don't have to tell GIT which files to worry about. It worries about the right ones naturally.
Using git
(adapted from http://www.kernel.org/pub/software/scm/git/docs/tutorial.html)
Register Yourself
git config --global user.name "Your Name Here" git config --global user.email you@your.org
Have GIT manage your existing code
cd your/project git init
Check the status of your code
git status
Add files to be managed by GIT
git add file1 file2 ...
Or, you can just use the -a
switch on git commit
. This will find any new files and automatically add them.
git commit -a
Commit your changes
git commit
Or to add any new files:
git commit -a
See the history
git log
Note that previous revisions are these really long strings. You only need like the first 8 or 10 to uniquely identify a revision, usually.
git show 266ef995c00
Shows what happened for this commit in detail.
git show HEAD
Shows what is on the HEAD.
git show 266ef995c00^
Shows the parent of 266ef995c00. ^^ = grandparent, ~4 = great-great grandparent.
git branch <new-branch> 266ef995c00
Starts a new branch named new-branch from the revision.
List branches
git branch
Asterisk (*) marks the branch you are on. master
is the original--mainline or the trunk in other systems.
Create a branch
git branch new-branch
Switch to a branch
git checkout branch-name
Note that when you switch, any files that are modified are preserved. That is, they won't change.
See what's on another branch
git show <branch>
Merge changes from another branch to this one
git merge branch-name
Start a project from someone else's project
git clone path-to-other-project new-path
Pull in changes form another project
git pull path-to-other-project [branch]
Or, if you've already named it with git remote add
git pull name
Using a remote repository
get remote add name path-to-remote-repo
Pulling in changes from a remote repo
get fetch name
TODO
You've Got Some Great Code But You Can't Commit
If you've got some great code you'd like to save, but you can't commit it to the current branch, do this.
- Save the code.
- git branch new-branch: Create a new branch
- git branch: This should show what branch you are on.
- git checkout new-branch: This will move you to new-branch. Your modified files don't change.
- git commit -a: This will commit all your changes to the new-branch. The other branch remains unchanged.
- git checkout old-branch: This will move you back to the old branch. Your files will revert to what they were before you made your most recent changes.
If you want to go back to working on the experimental code, you can commit/revert to get a clean slate, and then git checkout new-branch.
Creating a Release
This is what I've figured out.
I have two directories:
- ~/dev is my development directory. I work on the development version there. It's very unstable, until I have a mind to stabilize it and fix all the bugs. When I've got something that works, I am satisfied and plan on moving it to alpha.
- ~/alpha is where I run the alpha code. I want to keep this mostly stable. I would also pull in other's people changes in there if there were other developers. When I want to pull something in:
cd ~/alpha git pull ~/dev
Sometimes I find a bug. I fix it and commit it there. If I want to pull the fix back down to my development directory:
cd ~/dev git pull ~/alpha
This same pattern can be used for beta, etc...