Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
git:crash-course [2009/04/16 16:11] janakj created |
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, | + | configuration files to this page for your convenience, |
- | and .gitignore in your home directory. File sip-router.org_CA.pem is optional, | + | and file {{: |
- | you will only need the file if you plan on accessing the repository over https | + | |
- | (that' | + | |
Edit file '' | Edit file '' | ||
Line 29: | Line 27: | ||
name = Jan Janak | name = Jan Janak | ||
email = jan@iptel.org | email = jan@iptel.org | ||
+ | </ | ||
The git configuration file in your home directory sets up a bunch of short | The git configuration file in your home directory sets up a bunch of short | ||
Line 35: | 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 ' | + | and if you alias git to ' |
which is much more convenient. | which is much more convenient. | ||
Line 43: | 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 | + | '' |
look prettier: | look prettier: | ||
- | export GIT_PAGER=" | + | |
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', | + | ''git clone'', this is the command that is used to retrieve the sip-router |
repository from the server: | repository from the server: | ||
Line 55: | Line 54: | ||
Replace < | Replace < | ||
- | will be stored in 'sip-router' | + | will be stored in "sip-router" |
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 82: | 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 | + | of the repository. Most likely you will see just one branch called |
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 ' | + | one branch called '"master' |
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 | ||
- | ' | + | ' |
contains latest sip-router sources. | contains latest sip-router sources. | ||
- | Typically, the branch with the most up-to-date code is called ' | + | Typically, the branch with the most up-to-date code is called |
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 | + | NOTE: Branches are sometimes called |
- | just remember that 'branch' | + | just remember that "branch" |
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:// | http:// | ||
- | notice that there are more branches than the 'master' | + | notice that there are more branches than the "master" |
- | 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 |
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 108: | Line 107: | ||
The output should look roughly like this: | The output should look roughly like this: | ||
+ | < | ||
* master | * master | ||
origin/HEAD | origin/HEAD | ||
Line 122: | Line 122: | ||
origin/ | origin/ | ||
origin/ | origin/ | ||
+ | </ | ||
Branches that start with " | Branches that start with " | ||
repository. The string origin is just a short alias for the full URI of the | repository. The string origin is just a short alias for the full URI of the | ||
- | remote repository, such as ssh:// | + | remote repository, such as %%ssh:// |
convention that the repository you cloned from initially is called the origin. | convention that the repository you cloned from initially is called the origin. | ||
Line 138: | 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' | + | 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 " | lines starting with " | ||
- | 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 167: | Line 168: | ||
same commit: | same commit: | ||
- | $ 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 '' |
- | 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 177: | 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' | + | 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 191: | 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 | + | this operation is called |
- | remote repository with 'git push': | + | remote repository with ''git push'': |
$ git push origin master: | $ git push origin master: | ||
Line 202: | 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 | + | and in that case repository |
- | 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. |
- | 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. |
- | 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'' |
- | equivalent of 'cvs 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 229: | 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 | + | This command creates a new branch called |
- | track the master branch and checks the new branch out. The word 'track' | + | track the master branch and checks the new branch out. The word "track" |
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 |
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 | ||
- | 'mybranch' | + | "mybranch" |
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: | $ git push origin 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/ | + | "janakj/ |
repository only permits new " | repository only permits new " | ||
must start with your username. If you try: | must start with your username. If you try: | ||
Line 257: | 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 265: | 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 : | + | $ git push origin |
- | 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 | + | ====== |
- | =============== | + | We have a test repository at '' |
- | 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 283: | Line 283: | ||
http:// | http:// | ||
- | Further Reading | + | ====== |
- | =============== | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |