Difference between revisions of "Git"

From PaparazziUAV
Jump to: navigation, search
(Option 2: clone from github without an account)
(Added intro description and reorganized)
 
(53 intermediate revisions by 8 users not shown)
Line 1: Line 1:
How to use [http://git-scm.com/ git] with the [http://github.com/paparazzi/paparazzi/ papaprazzi master repo].
+
[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 help and resources ==
+
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").
There are tons of tutorials, etc. out 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.
 
 
 
To get an understanding off the git internals the [http://blip.tv/file/4094854 video Getting Git] is excellent.
 
  
More:
+
== Setting up Git ==
* [http://gitcasts.com/ git screencasts]
+
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.
* [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]
 
* [http://git.or.cz/course/svn.html Git crash course for SVN users]
 
* [http://help.github.com/git-cheat-sheets/ Git cheat sheets]
 
  
== Before You Start ==
+
== Getting the Paparazzi Git Repository ==
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.
+
'''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]'''.
  
=== Basic Git configuration ===
+
Otherwise use Option 2 to directly get the code.
First tell git your ''real name'' and your ''e-mail address''.  You should add these before you start using Git:
+
=== Option 1: Fork paparazzi to your own github repo and clone from there ===
  
git config --global user.name ''"Your Name"''
+
==== Set up a Github account ====
git config --global user.email ''you@yourdomain.example.com''
+
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.
  
=== Set up a Github account ===
+
==== Fork paparazzi and clone your new repo ====
If you want some [http://github.com/ github] awesomeness you have to set up an account there and set your github token.
+
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.
  
== Get the code ==
+
When you initially clone a repo to your local machine git gives this [http://help.github.com/remotes/ remote] repo the name ''origin''.
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 git@github.com:<your github username>/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 ===
+
Optionally you can give your remote a more descriptive name when cloning by adding the option -o:
If you already forked the paparazzi-software repo to your own github account:
+
  git clone -o <name> git@github.com:<your github username>/paparazzi.git
  git clone -o <username> git@github.com:<your github username>/paparazzi.git
 
  
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.
+
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 ====
+
==== Adding Remotes ====
Now you want to add the main repo as a remote with the name ''paparazzi'' to easily pull changes from there:
+
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 paparazzi git://github.com/paparazzi/paparazzi.git
+
  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:
 
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
+
  git remote add upstream git@github.com:paparazzi/paparazzi.git
  
=== Option 2: clone from github without an account ===
+
=== Option 2: Directly clone paparazzi without a github account ===
Otherwise clone directly from the [http://github.com/paparazzi/paparazzi/ master repo] (read-only):
+
Clone directly from the [http://github.com/paparazzi/paparazzi/ master repo] (read-only):
 
  git clone git://github.com/paparazzi/paparazzi.git
 
  git clone git://github.com/paparazzi/paparazzi.git
 
or if you are behind a firewall with an http proxy available:
 
or if you are behind a firewall with an http proxy available:
 
  git clone https://github.com/paparazzi/paparazzi.git
 
  git clone https://github.com/paparazzi/paparazzi.git
  
== Get to work ==
+
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.
Gitk is your friend if you want to visualize all branches and history:
+
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
 
  gitk --all
  
=== Pull and push ===
+
=== Updating from the main repository (pull) ===
To fetch the changes from the paparazzi master branch on github merge them run
+
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 pull paparazzi
+
 
 +
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
 
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.
  
=== Contribute ===
+
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'').
Please send us a pull request on github.
+
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.
 +
 
 +
 
 +
So the basic pattern looks something like this:
 +
#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 80: 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 94: 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 04: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: