Changes between Initial Version and Version 1 of UfoRevisionControlGit


Ignore:
Timestamp:
Jul 30, 2012, 9:32:54 AM (12 years ago)
Author:
Matthias Vogelgesang
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UfoRevisionControlGit

    v1 v1  
     1= Git Distributed Version Control =
     2
     3Git is a distributed version control system currently maintained by Junio C. Hamano. You can find valuable information
     4
     5* at the official [http://git-scm.com/ Git homepage]
     6* in the [http://git-scm.com/book Git Book]
     7* in the comprehensive [http://git-scm.com/docs Git Reference Manual]
     8
     9= General Git Workflow =
     10
     11For in-depth information on how to use various aspects of Git, please consult the excellent [http://git-scm.com/book Git book] and the comprehensive [http://git-scm.com/docs manual]. The very first thing you should do, is to setup your personal information as this is associated with all the commits you are about to produce. So simply add this with:
     12{{{
     13$ git config --global user.name "Your Name Here"
     14$ git config --global user.email "Your E-Mail Here"
     15}}}
     16
     17To checkout a project, there are two options depending on the overall accessibility of the projects' repository. If the project is ''publicly'' available, you can checkout ''anonymously'' with
     18{{{
     19$ git checkout http://ufo.kit.edu/git/repo-path
     20}}}
     21if the project is ''private'' you need to have your public SSH key be associated with the repository. If this is the case, you can checkout a project via SSH with
     22{{{
     23$ git checkout git@ufo.kit.edu:repo-path
     24}}}
     25
     26== Pulling remote changes ==
     27
     28Now, you have the complete projects' history and can start to build the project or develop contributions. In any case, you want to regularly keep up with the changes made by others, so if you haven't touched the code, you can simply pull in changes with
     29{{{
     30$ git pull
     31}}}
     32
     33== Commit changes locally ==
     34
     35To record changes, you need to ''stage'' the change by adding the affected files with
     36{{{
     37$ git add FILE [FILE ...]
     38}}}
     39and ''commit'' the staged changes with
     40{{{
     41$ git commit
     42}}}
     43Note that this two-step process easily allows you to organize your commits in a logical way by staging only relevant changes. If you are sure that all changes are relevant to a certain commit you can by-pass this and simply call
     44{{{
     45$ git commit -a
     46}}}
     47In any case you will be presented with an editor to insert a summary line and a detailed commit message.
     48
     49== Branches ==
     50
     51Branching with Git is cheap and should be used at all times. The main branch is called ''master'' and should be left untouched for most of the time. To branch off of it, simply type
     52{{{
     53$ git branch new-branch-name
     54}}}
     55and change to the new branch with
     56{{{
     57$ git checkout new-branch-name
     58}}}
     59You can now develop independently of the main branch that you should synchronize regularly as shown above. If you want to merge the changes in your branch either use
     60{{{
     61$ git merge master
     62}}}
     63to pull in changes and intermingle them with yours. If you want to have your changes always be together, you can replay the changes ''on top'' of the master branch with
     64{{{
     65$ git rebase master
     66}}}
     67however, you should ''never'' publish a branch that has been rebased, otherwise people pulling from you will get in trouble.
     68
     69== Push changes remotely ==
     70
     71Depending on the access rights to the repository you can push your changes back to the server with
     72{{{
     73$ git push
     74}}}
     75However, in some cases you won't have write rights to the master branch. You have several options here. First you can generate patches with
     76{{{
     77$ git format-patch master..new-branch-name
     78}}}
     79and send them to the maintainer. You can also put your changes on a server that is accessible to the maintainer and tell him the location. He can setup a remote branch and merge the changes himself. If you have an associated public key and the maintainer asked to have personal branches, you can push your changes with
     80{{{
     81$ git push origin new-branch-name:/dev/user-name/new-branch-name
     82}}}
     83The branch name in front of the colon is your ''local'' branch name, the one after is the ''remote'' branch name containing the path where you can store changes. If you want to delete the remote branch, you push an empty branch to the same location
     84{{{
     85$ git push origin :/dev/user-name/new-branch-name
     86}}}
     87
     88= Creating a New Repository =
     89
     90If you have a project that you want to have version controlled with Git open a new ticket with the Infrastructure component and add the following information:
     91* Repository name (very short)
     92* Repository description
     93* Maintainer
     94* Should people from outside be able to see it on http://ufo.kit.edu/repos?
     95* Should other developers be able to push to personal branches?
     96* Public keys and user names for all people that you want to have
     97  * write rights to master
     98  * read rights
     99  * write/read rights to certain branches
     100
     101When the repository has been created and your project is already version controlled with Git locally, just register the repository URL as the new origin
     102{{{
     103$ git remote add origin git@ufo.kit.edu:repo-name
     104$ git push
     105}}}
     106otherwise create a local Git repository
     107{{{
     108$ git init .
     109}}}
     110and commit all files
     111{{{
     112$ git add
     113$ git commit
     114}}}
     115and register the repository URL.
     116
     117= Best Practices and Tips =
     118
     119== Commit Message ==
     120
     121Never, ever exceed the 50-character limit of the commit message summary in the first line! If you keep it short and concise, browsing through the logs becomes much more easier. More detailed information about the commit can and should be presented in the commit messages' body that has a 80-character-per-line limitation. In any case, you should setup your editor to respect these limitations.
     122
     123== Aliases ==
     124
     125Aliases save you ''a lot'' of time if used properly. See for example [http://robots.thoughtbot.com/post/4747482956/streamline-your-git-workflow-with-aliases this] blog entry.