Difference between revisions of "Git"

From PaparazziUAV
Jump to: navigation, search
(update to new repo name)
(Added intro description and reorganized)
 
(58 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<span style="color:red"><strong><big>We will switch to git on 19.11.2010, the git repo might be changed/moved/deleted until then, best stick to SVN until then!</big></strong></span>
+
[http://git-scm.com/ Git] is a version control system used for software development.
 +
With Git, it's possible for everyone to contribute to the code under a main code repository.
 +
Paparazzi's Git repository is stored on GitHub.
 +
This page explains how to use Git in order to develop/contribute to [http://github.com/paparazzi/paparazzi/ Paparazzi].
 +
For those familiar with Subversion (SVN), note that Git is different SVN. There are similarities between the two, but they are different. For a good explanation on the differences, see [https://help.github.com/articles/what-are-the-differences-between-subversion-and-git/ here].
  
----
+
Git enables branching the code into branches. The [[RepositoryStructure]] page explains the various branches. The ''master'' branch is used for active development. Users can instead use the latest stable version (e.g. "v5.12").
  
 +
== Setting up Git ==
 +
There is a nice guide of how to [https://help.github.com/articles/set-up-git/#setting-up-git set up git] for use with Github.
  
How to use [http://git-scm.com/ git] with the [http://github.com/paparazzi/paparazzi/ papaprazzi master repo].
+
== Getting the Paparazzi Git Repository ==
 +
'''If you plan to contribute or just to push your own config to [http://github.com/ github] please use Option 1 to create your own account and fork the [http://github.com/paparazzi/paparazzi/ papaprazzi repo]'''.
  
== Git help and resources ==
+
Otherwise use Option 2 to directly get the code.
There are tons of tutorials, etc. out there...
+
=== Option 1: Fork paparazzi to your own github repo and clone from there ===
You can also get help on any Git command by doing '''<code>git ''command'' -h</code>''' or '''<code>git help ''command''</code>'''.
 
  
See [https://git.wiki.kernel.org/index.php/GitSvnCrashCourse Git - crash course] for an introduction into git for svn users. For git newbies the [https://git.wiki.kernel.org/index.php/GitCheatSheet Git CheatSheet] is also nice.
+
==== Set up a Github account ====
 +
If you want some [http://github.com/ github] awesomeness you have to create an account there and [http://help.github.com/set-up-git-redirect set up git].
 +
Do not forget to provide your ssh key and [http://help.github.com/set-your-user-name-email-and-github-token/ github token], otherwise you will not be able to access your repositories.
  
To get an understanding off the git internals the [http://blip.tv/file/4094854 video Getting Git] is excellent.
+
==== Fork paparazzi and clone your new repo ====
 +
To [http://help.github.com/fork-a-repo/ fork] paparazzi, just log in to github, go to the [http://github.com/paparazzi/paparazzi/ main papaprazzi software repository] and click fork at the top of the page.
 +
This created the new paparazzi repository on your own github account which you can now clone to your local machine.
  
More:
+
When you initially clone a repo to your local machine git gives this [http://help.github.com/remotes/ remote] repo the name ''origin''.
* [http://gitcasts.com/ git screencasts]
+
git clone git@github.com:<your github username>/paparazzi.git
* [http://help.github.com/ git help from github]
 
* [http://book.git-scm.com/index.html git communitiy book]
 
* [http://progit.org/book/ ProGit book]
 
* [http://gitready.com/ git ready - short tips]
 
* [http://gitref.org/ nice Git reference]
 
  
== Before You Start ==
+
Optionally you can give your remote a more descriptive name when cloning by adding the option -o:
Git is not an evolution of SVN (like SVN is from CVS). This may lead to a lot of extra headscratching among migraters.  You have been warned.
+
git clone -o <name> git@github.com:<your github username>/paparazzi.git
  
=== Basic Git configuration ===
+
The option ''-o <name>'' uses ''name'' to keep track of the repository instead of using the remote name ''origin''. You can name the remote for your own paparazzi fork according you your username and the paparazzi master repo ''upstream'' to avoid confusion.
First tell git your ''real name'' and your ''e-mail address''. You should add these before you start using Git:
 
  
git config --global user.name ''"Your Name"''
+
==== Adding Remotes ====
  git config --global user.email ''you@yourdomain.example.com''
+
Now you want to [https://help.github.com/articles/adding-a-remote add the main repo as a remote] with the name ''upstream'' to easily pull changes from there:
 +
  git remote add upstream git://github.com/paparazzi/paparazzi.git
 +
The above URL provides read-only access, if you are a dev and have write access to the main repo as well you want to use:
 +
git remote add upstream git@github.com:paparazzi/paparazzi.git
  
=== Set up a Github account ===
+
=== Option 2: Directly clone paparazzi without a github account ===
If you want some [http://github.com/ github] awesomeness you have to set up an account there and set your github token.
+
Clone directly from the [http://github.com/paparazzi/paparazzi/ master repo] (read-only):
 +
git clone git://github.com/paparazzi/paparazzi.git
 +
or if you are behind a firewall with an http proxy available:
 +
git clone https://github.com/paparazzi/paparazzi.git
  
== Get the code ==
+
This will name the remote Paparazzi repository ''origin''. You can add the option ''-o name'' to use ''name'' (e.g. ''upstream'') to keep track of the paparazzi master repo to avoid confusion.
If you plan to contribute or just to push your own config to github '''please first fork the [http://github.com/paparazzi/paparazzi/ papaprazzi repo] on github'''.
+
git clone -o upstream git://github.com/paparazzi/paparazzi.git
Just log in and click fork at the top of the main paparazzi software repository.
 
  
=== Option 1: clone from your own github repo ===
+
== Basic Git Commands ==
If you already forked the paparazzi-software repo to your own github account:
+
=== See what's going on ===
  git clone -o <username> git@github.com:<your github username>/paparazzi.git
+
To show the status (modified and staged changes) you can run
 +
  git status
  
The option ''-o <name>'' uses ''name'' to keep track of the upstream repository instead of using the remote name ''origin''. It is recommended to call the remote for the papaprazzi master repo ''paparazzi'' and name your own github remote according to your name to avoid confusion.
+
To list your branches and the corresponding upstream branch (the one marked with the star is the currently used branch):
 +
git branch -vv
  
==== Adding remotes ====
+
Gitk is your friend if you want to visualize all remotes/branches and history:
Now you want to add the main repo as a remote with the name ''paparazzi'' to easily pull changes from there:
+
  gitk --all
git remote add paparazzi git://github.com/paparazzi/paparazzi.git
 
The above URL provides read-only access, if you are a dev and have write access to the main repo as well you want to use:
 
  git remote add paparazzi git@github.com:paparazzi/paparazzi.git
 
  
=== Option 2: clone from github without an account ===
+
=== Updating from the main repository (pull) ===
Otherwise clone directly from the [http://github.com/paparazzi/paparazzi/ master repo] (read-only):
+
Have a look at the very good short overview of [http://gitready.com/beginner/2009/01/21/pushing-and-pulling.html pushing and pulling on gitready.com] and the [https://help.github.com/articles/syncing-a-fork syncing a fork article on github].
git clone git://github.com/paparazzi/paparazzi.git
 
  
== Get to work ==
+
To fetch the changes from the stable branch (e.g. currently v5.8) on github and merge them into your local branch run
Gitk is your friend if you want to visualize all branches and history:
+
git pull <remote> v5.8
gitk --all
+
Where <remote> is the name for the remote to the main Paparazzi repo and is usually ''upstream'' or ''origin'' depending on your earlier setup.
  
=== Pull and push ===
+
If you want to use the latest bleeding edge version, checkout out the ''master'' (development) branch:
To fetch the changes from the paparazzi master branch on github merge them run
+
git checkout master
  git pull paparazzi
+
To update it:
 +
  git pull upstream master
  
 +
=== Publishing your changes ===
 
To push your (already locally committed) changes to your own github master branch
 
To push your (already locally committed) changes to your own github master branch
  git push <remote> master
+
  git push <remote> <branch>
Where <remote> is the name for the remote to your own github repo and is <username> if you named it like explained above.
+
Where <remote> is the name for the remote to your own github repo and is usually ''origin'' or your username (depending on your earlier setup).<br\>
 +
And <branch> is the branch you want to push to your remote repository, either ''master'' or your topic branch.
 +
 
 +
== Contribute ==
 +
'''If you are working on a new feature, you should do all your work in a topic branch''' which then can be merged back into master when it is ready.
 +
If you are just working on a small fix for a specific release, you can do that from the branch for the respective version.
 +
Please send us a [http://help.github.com/send-pull-requests/ pull request] on github.
 +
 
 +
I you want to update your branch it is good practice (in most cases) to use ''git up'' (''git pull --rebase'') instead of ''git pull'' (See below to define ''git up'' as an alias for ''git pull --rebase'').
 +
This will [http://learn.github.com/p/rebasing.html rebase] your changes ontop of the current master instead of merging. It is very useful to keep the history more readable and make bug searching easier.
 +
 
  
=== Contribute ===
+
So the basic pattern looks something like this:
Please send us a pull request on github.
+
#Fetch the latest versions from the main repo: ''git fetch'' or ''git remote update'' to update all remotes
 +
#Create a new branch of the current ''master'' branch:<br>git checkout -b new_feature upstream/master
 +
#Add and commit changes to the new branch (with a [http://bit.ly/goodcommitmessages good commit message])
 +
#Rebase updates from upstream branch:<br>git up upstream/master
 +
#Push it to the repo when it is ready
 +
#send us a [http://help.github.com/pull-requests/ pull request]
  
 
== Advanced Configuration and helpful tools ==
 
== Advanced Configuration and helpful tools ==
Line 81: Line 105:
 
  git config --global alias.ci commit  # make `git ci` work
 
  git config --global alias.ci commit  # make `git ci` work
 
  git config --global alias.br branch  # make `git br` work
 
  git config --global alias.br branch  # make `git br` work
 +
git config --global alias.up "pull --rebase"  # make `git up` work similar to svn up
 +
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
  
 
=== Line endings ===
 
=== Line endings ===
Although you might think you’re immune to CRLF-ended files on mac and linux, you are not. It is possible to download files from an external source that use CRLF, and thus commit them into your repo. To be safe, you should set your config to convert line endings on commit so they are always LF in the repo:
+
Although you might think you’re immune to CRLF-ended files on mac and linux, you are not. It is possible to download files from an external source that use CRLF, and thus commit them into your repo. You should globally set your config to convert line endings on commit so they are always LF in the repo (or omit the --global for paparazzi only):
 
  git config --global core.autocrlf input
 
  git config --global core.autocrlf input
 
If you are on a windows box by any chance set:
 
If you are on a windows box by any chance set:
Line 95: Line 121:
  
 
For zsh: http://www.wunjo.org/zsh-git/
 
For zsh: http://www.wunjo.org/zsh-git/
 +
 +
[[Category:Software]] [[Category:Developer_Documentation]]
 +
 +
 +
== Git help and resources ==
 +
There are tons of tutorials, etc. out there... first check out the [http://git-scm.com/documentation git documentation].
 +
[[Image:Git.png|right|FixIt]]
 +
 +
You can also get help on any Git command by doing '''<code>git ''command'' -h</code>''' or '''<code>git help ''command''</code>'''.
 +
 +
'''Never used git before? Read (and watch) [http://learn.github.com/p/intro.html learn.github.com/p/intro.html].'''
 +
 +
To get an understanding off the git internals the [http://vimeo.com/14629850 "Getting Git" video by Scott Chacon] is excellent.
 +
 +
More:
 +
* [http://gitcasts.com/ git screencasts]
 +
* [http://help.github.com/ git help from github]
 +
* [https://git.wiki.kernel.org/index.php/GitSvnCrashCourse Git crash course for SVN users]
 +
* [http://gitready.com/ git ready - short tips]
 +
* [http://gitref.org/ nice Git reference]
 +
* [http://help.github.com/git-cheat-sheets/ more Git cheat sheets]

Latest revision as of 05:37, 28 November 2017

Git is a version control system used for software development. With Git, it's possible for everyone to contribute to the code under a main code repository. Paparazzi's Git repository is stored on GitHub. This page explains how to use Git in order to develop/contribute to Paparazzi. For those familiar with Subversion (SVN), note that Git is different SVN. There are similarities between the two, but they are different. For a good explanation on the differences, see here.

Git enables branching the code into branches. The RepositoryStructure page explains the various branches. The master branch is used for active development. Users can instead use the latest stable version (e.g. "v5.12").

Setting up Git

There is a nice guide of how to set up git for use with Github.

Getting the Paparazzi Git Repository

If you plan to contribute or just to push your own config to github please use Option 1 to create your own account and fork the papaprazzi repo.

Otherwise use Option 2 to directly get the code.

Option 1: Fork paparazzi to your own github repo and clone from there

Set up a Github account

If you want some github awesomeness you have to create an account there and set up git. Do not forget to provide your ssh key and github token, otherwise you will not be able to access your repositories.

Fork paparazzi and clone your new repo

To fork paparazzi, just log in to github, go to the main papaprazzi software repository and click fork at the top of the page. This created the new paparazzi repository on your own github account which you can now clone to your local machine.

When you initially clone a repo to your local machine git gives this remote repo the name origin.

git clone git@github.com:<your github username>/paparazzi.git

Optionally you can give your remote a more descriptive name when cloning by adding the option -o:

git clone -o <name> git@github.com:<your github username>/paparazzi.git

The option -o <name> uses name to keep track of the repository instead of using the remote name origin. You can name the remote for your own paparazzi fork according you your username and the paparazzi master repo upstream to avoid confusion.

Adding Remotes

Now you want to add the main repo as a remote with the name upstream to easily pull changes from there:

git remote add upstream git://github.com/paparazzi/paparazzi.git

The above URL provides read-only access, if you are a dev and have write access to the main repo as well you want to use:

git remote add upstream git@github.com:paparazzi/paparazzi.git

Option 2: Directly clone paparazzi without a github account

Clone directly from the master repo (read-only):

git clone git://github.com/paparazzi/paparazzi.git

or if you are behind a firewall with an http proxy available:

git clone https://github.com/paparazzi/paparazzi.git

This will name the remote Paparazzi repository origin. You can add the option -o name to use name (e.g. upstream) to keep track of the paparazzi master repo to avoid confusion.

git clone -o upstream git://github.com/paparazzi/paparazzi.git

Basic Git Commands

See what's going on

To show the status (modified and staged changes) you can run

git status

To list your branches and the corresponding upstream branch (the one marked with the star is the currently used branch):

git branch -vv

Gitk is your friend if you want to visualize all remotes/branches and history:

gitk --all

Updating from the main repository (pull)

Have a look at the very good short overview of pushing and pulling on gitready.com and the syncing a fork article on github.

To fetch the changes from the stable branch (e.g. currently v5.8) on github and merge them into your local branch run

git pull <remote> v5.8

Where <remote> is the name for the remote to the main Paparazzi repo and is usually upstream or origin depending on your earlier setup.

If you want to use the latest bleeding edge version, checkout out the master (development) branch:

git checkout master

To update it:

git pull upstream master

Publishing your changes

To push your (already locally committed) changes to your own github master branch

git push <remote> <branch>

Where <remote> is the name for the remote to your own github repo and is usually origin or your username (depending on your earlier setup).<br\> And <branch> is the branch you want to push to your remote repository, either master or your topic branch.

Contribute

If you are working on a new feature, you should do all your work in a topic branch which then can be merged back into master when it is ready. If you are just working on a small fix for a specific release, you can do that from the branch for the respective version. Please send us a pull request on github.

I you want to update your branch it is good practice (in most cases) to use git up (git pull --rebase) instead of git pull (See below to define git up as an alias for git pull --rebase). This will rebase your changes ontop of the current master instead of merging. It is very useful to keep the history more readable and make bug searching easier.


So the basic pattern looks something like this:

  1. Fetch the latest versions from the main repo: git fetch or git remote update to update all remotes
  2. Create a new branch of the current master branch:
    git checkout -b new_feature upstream/master
  3. Add and commit changes to the new branch (with a good commit message)
  4. Rebase updates from upstream branch:
    git up upstream/master
  5. Push it to the repo when it is ready
  6. send us a pull request

Advanced Configuration and helpful tools

If you want to inspect your global configuration, have a look at the .gitconfig file in your home directory.

The per repository configuration is stored in the .git/config file in your repository.

Colors and Aliases

You also might want to set some color options and aliases, e.g.:

git config --global color.ui auto     # colors for all
git config --global alias.st status   # make `git st` work
git config --global alias.co checkout # make `git co` work
git config --global alias.ci commit   # make `git ci` work
git config --global alias.br branch   # make `git br` work
git config --global alias.up "pull --rebase"   # make `git up` work similar to svn up
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

Line endings

Although you might think you’re immune to CRLF-ended files on mac and linux, you are not. It is possible to download files from an external source that use CRLF, and thus commit them into your repo. You should globally set your config to convert line endings on commit so they are always LF in the repo (or omit the --global for paparazzi only):

git config --global core.autocrlf input

If you are on a windows box by any chance set:

git config --global core.autocrlf true

Magit

If you are an emacs user you might want to have a look at http://philjackson.github.com/magit/

git status in shell

For bash: http://www.gitready.com/advanced/2009/01/23/bash-git-status.html

For zsh: http://www.wunjo.org/zsh-git/


Git help and resources

There are tons of tutorials, etc. out there... first check out the git documentation.

FixIt

You can also get help on any Git command by doing git command -h or git help command.

Never used git before? Read (and watch) learn.github.com/p/intro.html.

To get an understanding off the git internals the "Getting Git" video by Scott Chacon is excellent.

More: