Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
git:crash-course [2009/04/16 16:27]
janakj
git:crash-course [2011/09/14 09:33] (current)
87.95.106.127 [Git Crash Course For sip-router]
Line 11: Line 11:
  
 As the second step you need to configure the git client. I have attached As the second step you need to configure the git client. I have attached
-configuration files to this email for your convenience, save files .gitconfig +configuration files to this page for your convenience, save file {{:git:gitconfig.sample|.gitconfig.sample}} as ''.gitconfig'' 
-and .gitignore in your home directory. File sip-router.org_CA.pem is optional, +and file {{:git:gitignore.sample|.gitignore.sample}} as ''.gitignore'' in your home directory. File {{:git:sip-router.org_ca.pem|sip-router.org_CA.pem}} is optional, it should be saved in a directory with SSL certificates (usually ''/etc/ssl/certs''). You will only need the file if you plan on accessing the repository over https (that's not the case for developers with write access). 
-you will only need the file if you plan on accessing the repository over https +
-(that's not the case for developers with write access). +
  
 Edit file ''~/.gitconfig'' and configure your name and email address there. This Edit file ''~/.gitconfig'' and configure your name and email address there. This
Line 36: Line 34:
   $ git checkout   $ git checkout
  
-every time you are checking out a branch, you can just type 'git co' instead, +every time you are checking out a branch, you can just type ''git co'' instead, 
-and if you alias git to 'g' in your ~/.bashrc then it becomes just 'g co'+and if you alias git to 'g' in your ~/.bashrc then it becomes just ''g co''
 which is much more convenient. which is much more convenient.
  
Line 44: Line 42:
 and less is configured to use 8 spaces for tabs by default. We use 4 spaces in and less is configured to use 8 spaces for tabs by default. We use 4 spaces in
 our sources and thus you might want to re-configure the git pager in your our sources and thus you might want to re-configure the git pager in your
-~/.bashrc. The following setting makes the output of 'git diff' and friends+''~/.bashrc''. The following setting makes the output of 'git diff' and friends
 look prettier: look prettier:
  
Line 50: Line 48:
  
 Now you can start working with git. The first command that you need to run is Now you can start working with git. The first command that you need to run is
-'git clone', this is the command that is used to retrieve the sip-router+''git clone'', this is the command that is used to retrieve the sip-router
 repository from the server: repository from the server:
  
Line 56: Line 54:
  
 Replace <username> with your real username. The contents of the repository Replace <username> with your real username. The contents of the repository
-will be stored in 'sip-routersubdirectory of your current working directory.+will be stored in "sip-routersubdirectory of your current working directory.
 This command is the git equivalent of cvs/svn checkout. Like cvs/svn it will This command is the git equivalent of cvs/svn checkout. Like cvs/svn it will
 make the most recent version of the sources available in the make the most recent version of the sources available in the
Line 83: Line 81:
  
 The command above shows a list of branches that are present in your local copy The command above shows a list of branches that are present in your local copy
-of the repository. Most likely you will see just one branch called 'master'+of the repository. Most likely you will see just one branch called "master"
 marked with an asterisk. This means that your local repository contains only marked with an asterisk. This means that your local repository contains only
-one branch called 'master' and the asterisk tells you that this is the branch+one branch called '"master'and the asterisk tells you that this is the branch
 that is currently checked out. So the sources that you see in that directory that is currently checked out. So the sources that you see in that directory
 come from the master branch. The local master branch is an exact copy of the come from the master branch. The local master branch is an exact copy of the
-'master' branch from the remote repository at git.sip-router.org and it+'master' branch from the remote repository at ''git.sip-router.org'' and it
 contains latest sip-router sources. contains latest sip-router sources.
  
-Typically, the branch with the most up-to-date code is called 'master' in+Typically, the branch with the most up-to-date code is called ''master'' in
 git. It is the git equivalent of CVS HEAD branch and SVN trunk branch. git. It is the git equivalent of CVS HEAD branch and SVN trunk branch.
  
-NOTE: Branches are sometimes called 'headsin git documentation, but you can +NOTE: Branches are sometimes called "headsin git documentation, but you can 
-just remember that 'branchand 'headrefers to the same thing.+just remember that "branchand "headrefers to the same thing.
  
 If you look at the remote version of the repository with gitweb at If you look at the remote version of the repository with gitweb at
 http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=heads you will http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=heads you will
-notice that there are more branches than the 'masterbranch which was created +notice that there are more branches than the "masterbranch which was created 
-by 'git clone' in the local copy of the repository. The command 'git clone'+by ''git clone'' in the local copy of the repository. The command ''git clone''
 only makes the master branch directly available in the local copy of the only makes the master branch directly available in the local copy of the
 repository. For other branches it merely records the fact that the branches repository. For other branches it merely records the fact that the branches
Line 109: Line 107:
  
 The output should look roughly like this: The output should look roughly like this:
 +<code>
 * master * master
   origin/HEAD   origin/HEAD
Line 123: Line 122:
   origin/janakj/doxygen   origin/janakj/doxygen
   origin/master   origin/master
 +</code>
  
 Branches that start with "origin/" are branches that exist in the remote Branches that start with "origin/" are branches that exist in the remote
Line 139: Line 139:
   $ git commit   $ git commit
  
-As you can see above you need to call 'git add' before you call 'git +As you can see above you need to call ''git add'' before you call ''git 
-commit'. 'git add' marks your changes to be commited during the next commit,+commit''''git add'' marks your changes to be commited during the next commit,
 this is useful, for example, if you want to leave some local changes this is useful, for example, if you want to leave some local changes
 uncommited while you make the commit. Unlike CVS or SVN, git does not assume uncommited while you make the commit. Unlike CVS or SVN, git does not assume
 that all local changes should be commited during the next commit. It lets you that all local changes should be commited during the next commit. It lets you
 explicitly select a set of changes to be commited. You can avoid the need to explicitly select a set of changes to be commited. You can avoid the need to
-call two commands with 'git commit -a', see the git documentation for more+call two commands with ''git commit -a'', see the git documentation for more
 details. details.
  
 When you are done with the commit, you can display the list of changes in the When you are done with the commit, you can display the list of changes in the
-repository with 'git log'. The command displays the history of changes in the+repository with ''git log''. The command displays the history of changes in the
 whole repository, if you want to limit the list to main.c only then you can whole repository, if you want to limit the list to main.c only then you can
-run 'git log main.c'.+run ''git log main.c''.
  
-If you look closely at the output of 'git log' then you will notice strange+If you look closely at the output of ''git log'' then you will notice strange
 lines starting with "commit" followed by a long string of characters: lines starting with "commit" followed by a long string of characters:
  
- commit 0253726f99ac151f748712a5d39d71f42d9defc6+  commit 0253726f99ac151f748712a5d39d71f42d9defc6
  
 The long string is how commits in git are represented. This string is a SHA1 The long string is how commits in git are represented. This string is a SHA1
Line 168: Line 168:
 same commit: same commit:
  
- $ git diff b0f6ec8784712e4c1436fc9a4a3b54296e94ba5c +  $ git diff b0f6ec8784712e4c1436fc9a4a3b54296e94ba5c 
- $ git diff b0f6e+  $ git diff b0f6e
  
-If somebody creates another commit with an SHA1 id starting with b0f6e later +If somebody creates another commit with an SHA1 id starting with ''b0f6e'' later 
-then 'git diff b0f6e' would not longer work and git would complain that the+then ''git diff b0f6e'' would not longer work and git would complain that the
 prefix is ambiguous. prefix is ambiguous.
  
Line 178: Line 178:
 only. There is absolutely no communication with the the remote repository in only. There is absolutely no communication with the the remote repository in
 any of the commands above (git add, git commit, git log). This is possible any of the commands above (git add, git commit, git log). This is possible
-because we created a full copy of the remote repository with 'git clone'. This+because we created a full copy of the remote repository with ''git clone''. This
 is also the reason why all the commands are so fast, unlike their equivalents is also the reason why all the commands are so fast, unlike their equivalents
 in CVS or SVN. in CVS or SVN.
Line 192: Line 192:
 them available to others. This can be done by uploading your local changes to them available to others. This can be done by uploading your local changes to
 the remote repository (the one you initially cloned from). In git terminology the remote repository (the one you initially cloned from). In git terminology
-this operation is called 'push', so you can push your local changes to the +this operation is called "push", so you can push your local changes to the 
-remote repository with 'git push':+remote repository with ''git push'':
  
   $ git push origin master:master   $ git push origin master:master
Line 203: Line 203:
   $ git push origin   $ git push origin
  
-and then 'git push' will upload all local branches to the remote+and then ''git push'' will upload all local branches to the remote
 repository. You can also omit the first parameter: repository. You can also omit the first parameter:
  
   $ git push   $ git push
  
-and in that case repository 'originis used.+and in that case repository "originis used.
  
-The opposite of 'git push' is 'git pull'. This is the operation that you can +The opposite of ''git push'' is ''git pull''. This is the operation that you can 
-use to synchronize your local repository with the remote repository. 'git +use to synchronize your local repository with the remote repository. ''git 
-pull' downloads all changes (made by others) from the remote repository that+pull'' downloads all changes (made by others) from the remote repository that
 are not yet in your local repository and integrates them into your local are not yet in your local repository and integrates them into your local
-repository. You can run 'git pull' whenever you are online to fetch latest+repository. You can run ''git pull'' whenever you are online to fetch latest
 changes and keep your local copy of the repository up-to-date. changes and keep your local copy of the repository up-to-date.
  
-'git push' and 'git pull' are similar to rsync, they update either the local +''git push'' and ''git pull'' are similar to rsync, they update either the local 
-or the remote copy of the repository by tranferring only what is missing. 'git +or the remote copy of the repository by tranferring only what is missing. ''git 
-push' is the git equivalent of 'cvs ci' and 'svn ci'. 'git pull' is the git +push'' is the git equivalent of ''cvs ci'' and ''svn ci''''git pull'' is the git 
-equivalent of 'cvs update' or 'svn update'.+equivalent of ''cvs update'' or ''svn update''.
  
 If you make only small changes to the repository then you can modify the If you make only small changes to the repository then you can modify the
Line 230: Line 230:
 operations. You do not even have to push your local branches into the remote operations. You do not even have to push your local branches into the remote
 repository, you can just keep them in the local copy for your own repository, you can just keep them in the local copy for your own
-purposes. You can create a new branch in your local repository with 'git checkout':+purposes. You can create a new branch in your local repository with ''git checkout'':
  
   $ git checkout --track -b mybranch master   $ git checkout --track -b mybranch master
  
-This command creates a new branch called 'mybranch', configures the branch to +This command creates a new branch called "mybranch", configures the branch to 
-track the master branch and checks the new branch out. The word 'trackin+track the master branch and checks the new branch out. The word "trackin
 this context means that the newly created branch will receive all updates from this context means that the newly created branch will receive all updates from
-the master branch whenever you run 'git pull' with this branch checked out. In+the master branch whenever you run ''git pull'' with this branch checked out. In
 other words, the branch tracks another branch (master in this case) by merging other words, the branch tracks another branch (master in this case) by merging
-all changes from the original branch. Command line option -b instructs git to+all changes from the original branch. Command line option ''-b'' instructs git to
 to create a new branch. If this option was omitted then git would assume that to create a new branch. If this option was omitted then git would assume that
-'mybranchis an existing branch and it would try to check the branch out.+"mybranchis an existing branch and it would try to check the branch out.
  
 The newly created branch exists in the local repository only. If you want to The newly created branch exists in the local repository only. If you want to
-push the branch to the remote repository then you can use 'git push' again:+push the branch to the remote repository then you can use ''git push'' again:
  
   $ git push origin mybranch:janakj/mybranch   $ git push origin mybranch:janakj/mybranch
  
 Because mybranch is a private topic branch of mine, I am pushing it as Because mybranch is a private topic branch of mine, I am pushing it as
-janakj/mybranch to the remote repository at git.sip-router.org. The remote+"janakj/mybranchto the remote repository at ''git.sip-router.org''. The remote
 repository only permits new "username" branches. In other words their name repository only permits new "username" branches. In other words their name
 must start with your username. If you try: must start with your username. If you try:
Line 258: Line 258:
 place is because we wanted to make sure that people do not push all local place is because we wanted to make sure that people do not push all local
 branches to the remote repository by accident. This can easily happen if you branches to the remote repository by accident. This can easily happen if you
-run 'git push' without any parameters.+run ''git push'' without any parameters.
  
 You can also delete a local branch that is no longer needed by running You can also delete a local branch that is no longer needed by running
Line 266: Line 266:
 This will delete the local branch only. If you pushed the branch to the remote This will delete the local branch only. If you pushed the branch to the remote
 repository then you might also want to delete the branch in the remote repository then you might also want to delete the branch in the remote
-repository with 'git push':+repository with ''git push'':
  
-  $ git push :janakj/mybranch+  $ git push origin :janakj/mybranch
  
-This is a special syntax of 'git push', if you omit the name of the local +This is a special syntax of ''git push'', if you omit the name of the local 
-branch then 'git push' deletes the remote branch whose name follows ':'.+branch then ''git push'' deletes the remote branch whose name follows ":".
  
 ====== Test Repository ====== ====== Test Repository ======
-We have a test repository at git.sip-router.org which you can use to test+We have a test repository at ''git.sip-router.org'' which you can use to test
 various git operations. Clone the repository with: various git operations. Clone the repository with:
      
Line 288: Line 288:
   - Git SVN Crashcourse: http://git.or.cz/course/svn.html   - Git SVN Crashcourse: http://git.or.cz/course/svn.html
   - http://git-scm.com/documentation   - http://git-scm.com/documentation
- 
  

Navigation

Wiki

Other

QR Code
QR Code git:crash-course (generated for current page)