Already a member?
Sign in
Version Control
Git
1. response-time / performance (very easy to work locally to make
commits fast)
2. agility (easy to make branches and makes you a faster programmer)
3. distributed, so you can synchronize with your laptop, desktop,
friend's computer, or work computer without having to always connect
to a centralized server.
You can do all of these things with SVN, but git just makes it a lot
easier to. You can think of git as the "sqlite3" of databases.
website: git.or.cz
author: Linus Torvalds, the guy who wrote 2% of the LInux kernel.
Features of git:
----------
offline: All files are committed with respect to a local repository.
Therefore, git can always be used offline. No need for central server
or internet.
distributed: can share git repository with peers -- not just server.
agile branching: branching becomes easier than in SVN: makes you more agile
emphasizes content not files
INSTALLATION
For OS X, use MacPorts:
sudo port install git-core
Others:
install from source. good luck. ;)
Latest:
git clone git://git.kernel.org/pub/scm
1. response-time / performance (very easy to work locally to make
commits fast)
2. agility (easy to make branches and makes you a faster programmer)
3. distributed, so you can synchronize with your laptop, desktop,
friend's computer, or work computer without having to always connect
to a centralized server.
You can do all of these things with SVN, but git just makes it a lot
easier to. You can think of git as the "sqlite3" of databases.
website: git.or.cz
author: Linus Torvalds, the guy who wrote 2% of the LInux kernel.
Features of git:
----------
offline: All files are committed with respect to a local repository.
Therefore, git can always be used offline. No need for central server
or internet.
distributed: can share git repository with peers -- not just server.
agile branching: branching becomes easier than in SVN: makes you more agile
emphasizes content not files
INSTALLATION
For OS X, use MacPorts:
sudo port install git-core
Others:
install from source. good luck. ;)
Latest:
git clone git://git.kernel.org/pub/scm
/git/git.git
CONFIGURE
identify yourself to git: email and your name
git config --global user.name "David Beckwith"
git config --global user.email "dbitsolutions@gmail.com"
To view all users:
git config --list
OR
cat .gitconfig
SET UP ALIASES
git config --global alias.co checkout
VIEW YOUR CONFIGURATION
cat .gitconfig
TO IGNORE WHITESPACE (Ruby is whitespace insensitive)
git config --global apply.whitespace nowarn
Some nice aliases:
gb = git branch
gba = git branch -a
gc = git commit -v
gd = git diff | mate
gl = git pull
gp = git push
gst = git status
START USING GIT:
git init
TO IGNORE SOME FILES MAKE A FILE (in the root directory) CALLED
.gitignore and add some files to it:
# comments begin with hash.
*.log
db/schema.rb
db/schema.sql
TO SCHEDULE THE ADDITION OF ALL FILES TO THE NEXT COMMIT:
git add .
TO SEE WHAT THE STATUS:
git status
TO COMMIT:
git commit -m "First import"
TO SEE WHAT HAS BEEN COMMITTED:
git ls-files
TO SCHEDULE DELETION OF A FILE:
git rm <file name>
TO COMMIT ALL CHANGES IN FILES IN THE CURRENT REPOSITORY:
git commit -a
TO SCHEDULE THE ADDITION OF AN INDIVIDUAL FILE TO THE NEXT COMMIT:
git add <file name>
TO VIEW THE DIFFERENCE AS YOU COMMIT USE THE -v OPTION
git commit -v
TO COMMIT AND TYPE THE MESSAGE ON THE COMMAND LINE USE THE -m OPTION
git commit -m "This is the message describing the commit"
TO COMMIT AND GET AUTOMATICALLY ANY CHANGES FROM OTHER PEOPLE USE THE -a OPTION
git commit -a
THE NORMAL COMMIT COMMAND:
git commit -a -v
TO VIEW A LOG OF YOUR COMMITS
git log
TO VIEW A LOG OF YOUR COMMITS WITH A GRAPH TO SHOW THE EXTENT OF THE CHANGES
git log --stat
TO HAVE PAGINATION WHEN VIEWING THE LOG FILE USE THE -v OPTION
git log -v
TO VISUALIZE YOUR CHANGES
gitk --all
TO CREATE A NEW BRANCH:
git branch <name of your new branch>
TO VIEW ALL OF THE EXISTING BRANCHES
git branch
TO VIEW A LIST OF ALL BRANCHES
git branch -a
TO SWITCH TO ANOTHER BRANCH. The state of your file system will
change after executing this command.
git checkout <name of the branch you want to switch to>
OR
git co <name of the branch you want to switch to>
TO MAKE SURE THAT YOUR NEW BRANCH GETS CHANGES FROM THE MASTER BRANCH
(WHERE EVERYBODY ELSE IS WORKING) USE THE REBASE COMMAND:
git rebase master
TO MERGE YOUR NEW BRANCH INTO THE MASTER BRANCH.
# first switch back to the master branch.
git co master
# check to see what changes you're about to merge together, compare
the two branches:
git diff master xyz
# if you're in the xyz branch, and want to merge the xyz branch into it.
git merge xyz
TO REVERT YOUR CHANGES to before the merge.
git reset --hard ORIG_HEAD
TO RESOLVE CONFLICTS just edit your file. Remove the markings, add
the file, then commit.
TO CREATE A BRANCH AND SWITCH TO THE BRANCH IN ONE MOVE:
git checkout -b <name of new branch>
TO CREATE A "CLIPBOARD" or "STASH" OF CHANGES THAT ARE NOT YET
COMMITED (SO THAT YOU CAN SWITCH TO ANOTHER BRANCH IN THE MIDDLE OF
YOUR CHANGES.), CREATE A STASH.
git stash "Put a message here to remind you of what you're saving to
the clipboard"
TO SWITCH AWAY FROM THE CURRENT BRANCH
git co <branch you want to switch to>
# do whatever
# switch back to the stashed branch
git co <the stashed branch>
TO VIEW THE LIST OF STASHES
git stash list
TO LOAD BACK THE "CLIPBOARD" OR "STASH"
git stash apply
# now you can continue to work where you were previously.
TO DELETE A BRANCH THAT IS NOT USED ANYMORE, but already merged into
the current branch. (TO CLEAN UP)
git branch -d <name of branch you want to delete>
TO DELETE AN UNMERGED BRANCH
git branch -D <name of branch you want to delete>
TO DELETE THE STASH. (ERASE THE "CLIPBOARD" FROM MEMORY)
git stash clear
TO SET UP YOUR REPOSITORY FOR SHARING ON A CENTRAL SERVER
# Copy up your repository. e.g.:
scp -r my_project deploy@yourbox.com:my_project
# Move your files on the remote server to /var/git/my_project
# For security make the owner of this project git
# On the repository server:
sudo chown -R git:git my_project
# then (for security) restrict the "deploy" user to doing git-related
things in /etc/passwd with a git-shell.
TO CHECK OUT THE GIT REPOSITORY TO YOUR LOCALHOST. ON YOUR LOCAL HOST do this:
git clone git@yourbox.com:/var/git/my_project
TO SEE SOME INFO ABOUT THE REPOSITORY THAT WILL TELL YOU WHICH
REPOSITORY IS THE MASTER AND WHICH IS THE SLAVE:
cat .git/config
# By virtue of having cloned the remote repository, your local
repository becomes the slave and will track and synchronize with the
remote master branch.
TO UPDATE YOUR LOCAL BRANCH FROM THE REMOTE SERVER:
git pull
TO GET A COPY OF THE ENTIRE REMOTE REPOSITORY (e.g. a repository named
"laptop") WITHOUT MERGING THEM INTO YOUR LOCAL BRANCHES USE FETCH
git fetch laptop
TO MERGE TWO LOCAL BRANCHES (ie. your local xyz branch with your local
master branch) USE MERGE
git merge laptop/xyz
# this merged the (already copied laptop repository's xyz branch) with
the current branch you're sitting in.
TO MERGE THE REMOTE BRANCH WITH YOUR LOCAL BRANCH THAT YOU ARE SITTING
IN USE PULL
TO ADD LOCAL KNOWLEDGE (TO YOUR LOCAL REPOSITORY) OF A 2ND REMOTE
REPOSITORY, LIKE YOUR LAPTOP
git remote add laptop duo2book.local:repos/m_project
# "laptop" is the name of the remote repository. "duo2book.local" is
the name of the machine, I guess
TO VIEW META INFORMATION ABOUT THAT REMOTE REPOSITORY
git remote show laptop
TOP PUSH A COMMITTED LOCAL CHANGE OF THE xyz BRANCH TO THE REMOTE laptop BRANCH
git push laptop xyz
TO CREATE A TRACKING BRANCH (A SLAVE BRANCH). Ie. to link a local
branch to a remote branch:
git branch --track <local name of branch> <remote name of branch>
NOW IF YOU'RE SITTING IN THE LOCAL TRACKING BRANCH, TO PULL YOU DON'T
NEED TO SPECIFY THE REMOTE TRACKING BRANCH:
git pull
# Note: you can tracking different branches from different remote
machines. For example, you can track your friend's "upgrade" branch
and track the "master" branch from your main webserver.
# By convention, 'origin' is the 'centralized server' which is the way
SVN is usually set up on a remote server.
TO SEE WHICH LOCAL BRANCHES ARE TRACKING A REMOTE BRANCH:
git remote show origin
TO WORK WITH AN SVN REPOSITORY BUT WORK WITH GIT LOCALLY:
git-svn clone <http location of an svn repository>
# Now you can work with the checked out directory as though it was a
git repository. (cuz it is)
TO PUSH (COMMIT) CHANGES TO THE REMOTE SERVER
git-svn dcommit
TO UPDATE YOUR LOCAL REPOSITORY FROM THE SVN REPOSITORY
git-svn rebase
# NOTE: make sure you have your perl bindings to your local svn installation.
CONFIGURE
identify yourself to git: email and your name
git config --global user.name "David Beckwith"
git config --global user.email "dbitsolutions@gmail.com"
To view all users:
git config --list
OR
cat .gitconfig
SET UP ALIASES
git config --global alias.co checkout
VIEW YOUR CONFIGURATION
cat .gitconfig
TO IGNORE WHITESPACE (Ruby is whitespace insensitive)
git config --global apply.whitespace nowarn
Some nice aliases:
gb = git branch
gba = git branch -a
gc = git commit -v
gd = git diff | mate
gl = git pull
gp = git push
gst = git status
START USING GIT:
git init
TO IGNORE SOME FILES MAKE A FILE (in the root directory) CALLED
.gitignore and add some files to it:
# comments begin with hash.
*.log
db/schema.rb
db/schema.sql
TO SCHEDULE THE ADDITION OF ALL FILES TO THE NEXT COMMIT:
git add .
TO SEE WHAT THE STATUS:
git status
TO COMMIT:
git commit -m "First import"
TO SEE WHAT HAS BEEN COMMITTED:
git ls-files
TO SCHEDULE DELETION OF A FILE:
git rm <file name>
TO COMMIT ALL CHANGES IN FILES IN THE CURRENT REPOSITORY:
git commit -a
TO SCHEDULE THE ADDITION OF AN INDIVIDUAL FILE TO THE NEXT COMMIT:
git add <file name>
TO VIEW THE DIFFERENCE AS YOU COMMIT USE THE -v OPTION
git commit -v
TO COMMIT AND TYPE THE MESSAGE ON THE COMMAND LINE USE THE -m OPTION
git commit -m "This is the message describing the commit"
TO COMMIT AND GET AUTOMATICALLY ANY CHANGES FROM OTHER PEOPLE USE THE -a OPTION
git commit -a
THE NORMAL COMMIT COMMAND:
git commit -a -v
TO VIEW A LOG OF YOUR COMMITS
git log
TO VIEW A LOG OF YOUR COMMITS WITH A GRAPH TO SHOW THE EXTENT OF THE CHANGES
git log --stat
TO HAVE PAGINATION WHEN VIEWING THE LOG FILE USE THE -v OPTION
git log -v
TO VISUALIZE YOUR CHANGES
gitk --all
TO CREATE A NEW BRANCH:
git branch <name of your new branch>
TO VIEW ALL OF THE EXISTING BRANCHES
git branch
TO VIEW A LIST OF ALL BRANCHES
git branch -a
TO SWITCH TO ANOTHER BRANCH. The state of your file system will
change after executing this command.
git checkout <name of the branch you want to switch to>
OR
git co <name of the branch you want to switch to>
TO MAKE SURE THAT YOUR NEW BRANCH GETS CHANGES FROM THE MASTER BRANCH
(WHERE EVERYBODY ELSE IS WORKING) USE THE REBASE COMMAND:
git rebase master
TO MERGE YOUR NEW BRANCH INTO THE MASTER BRANCH.
# first switch back to the master branch.
git co master
# check to see what changes you're about to merge together, compare
the two branches:
git diff master xyz
# if you're in the xyz branch, and want to merge the xyz branch into it.
git merge xyz
TO REVERT YOUR CHANGES to before the merge.
git reset --hard ORIG_HEAD
TO RESOLVE CONFLICTS just edit your file. Remove the markings, add
the file, then commit.
TO CREATE A BRANCH AND SWITCH TO THE BRANCH IN ONE MOVE:
git checkout -b <name of new branch>
TO CREATE A "CLIPBOARD" or "STASH" OF CHANGES THAT ARE NOT YET
COMMITED (SO THAT YOU CAN SWITCH TO ANOTHER BRANCH IN THE MIDDLE OF
YOUR CHANGES.), CREATE A STASH.
git stash "Put a message here to remind you of what you're saving to
the clipboard"
TO SWITCH AWAY FROM THE CURRENT BRANCH
git co <branch you want to switch to>
# do whatever
# switch back to the stashed branch
git co <the stashed branch>
TO VIEW THE LIST OF STASHES
git stash list
TO LOAD BACK THE "CLIPBOARD" OR "STASH"
git stash apply
# now you can continue to work where you were previously.
TO DELETE A BRANCH THAT IS NOT USED ANYMORE, but already merged into
the current branch. (TO CLEAN UP)
git branch -d <name of branch you want to delete>
TO DELETE AN UNMERGED BRANCH
git branch -D <name of branch you want to delete>
TO DELETE THE STASH. (ERASE THE "CLIPBOARD" FROM MEMORY)
git stash clear
TO SET UP YOUR REPOSITORY FOR SHARING ON A CENTRAL SERVER
# Copy up your repository. e.g.:
scp -r my_project deploy@yourbox.com:my_project
# Move your files on the remote server to /var/git/my_project
# For security make the owner of this project git
# On the repository server:
sudo chown -R git:git my_project
# then (for security) restrict the "deploy" user to doing git-related
things in /etc/passwd with a git-shell.
TO CHECK OUT THE GIT REPOSITORY TO YOUR LOCALHOST. ON YOUR LOCAL HOST do this:
git clone git@yourbox.com:/var/git/my_project
TO SEE SOME INFO ABOUT THE REPOSITORY THAT WILL TELL YOU WHICH
REPOSITORY IS THE MASTER AND WHICH IS THE SLAVE:
cat .git/config
# By virtue of having cloned the remote repository, your local
repository becomes the slave and will track and synchronize with the
remote master branch.
TO UPDATE YOUR LOCAL BRANCH FROM THE REMOTE SERVER:
git pull
TO GET A COPY OF THE ENTIRE REMOTE REPOSITORY (e.g. a repository named
"laptop") WITHOUT MERGING THEM INTO YOUR LOCAL BRANCHES USE FETCH
git fetch laptop
TO MERGE TWO LOCAL BRANCHES (ie. your local xyz branch with your local
master branch) USE MERGE
git merge laptop/xyz
# this merged the (already copied laptop repository's xyz branch) with
the current branch you're sitting in.
TO MERGE THE REMOTE BRANCH WITH YOUR LOCAL BRANCH THAT YOU ARE SITTING
IN USE PULL
TO ADD LOCAL KNOWLEDGE (TO YOUR LOCAL REPOSITORY) OF A 2ND REMOTE
REPOSITORY, LIKE YOUR LAPTOP
git remote add laptop duo2book.local:repos/m_project
# "laptop" is the name of the remote repository. "duo2book.local" is
the name of the machine, I guess
TO VIEW META INFORMATION ABOUT THAT REMOTE REPOSITORY
git remote show laptop
TOP PUSH A COMMITTED LOCAL CHANGE OF THE xyz BRANCH TO THE REMOTE laptop BRANCH
git push laptop xyz
TO CREATE A TRACKING BRANCH (A SLAVE BRANCH). Ie. to link a local
branch to a remote branch:
git branch --track <local name of branch> <remote name of branch>
NOW IF YOU'RE SITTING IN THE LOCAL TRACKING BRANCH, TO PULL YOU DON'T
NEED TO SPECIFY THE REMOTE TRACKING BRANCH:
git pull
# Note: you can tracking different branches from different remote
machines. For example, you can track your friend's "upgrade" branch
and track the "master" branch from your main webserver.
# By convention, 'origin' is the 'centralized server' which is the way
SVN is usually set up on a remote server.
TO SEE WHICH LOCAL BRANCHES ARE TRACKING A REMOTE BRANCH:
git remote show origin
TO WORK WITH AN SVN REPOSITORY BUT WORK WITH GIT LOCALLY:
git-svn clone <http location of an svn repository>
# Now you can work with the checked out directory as though it was a
git repository. (cuz it is)
TO PUSH (COMMIT) CHANGES TO THE REMOTE SERVER
git-svn dcommit
TO UPDATE YOUR LOCAL REPOSITORY FROM THE SVN REPOSITORY
git-svn rebase
# NOTE: make sure you have your perl bindings to your local svn installation.
websig |
Latest page update: made by websig
, Mar 21 2008, 6:13 PM EDT
(about this update
About This Update
Edited by websig
1327 words added view changes - complete history) |
|
Keyword tags:
None
More Info: links to this page
|