Difference between revisions of "Git For Developers"

From Net-SNMP Wiki
Jump to: navigation, search
(Pulling the latest changes from the upstream)
Line 34: Line 34:
 
=== Pulling the latest changes from the upstream ===
 
=== Pulling the latest changes from the upstream ===
  
Whether or not you've modified files locally and checked in the changes to your local repository, you'll need to occasionally pull down any changes that others have made upstream.  You do this with a ''pull'':
+
Whether or not you've modified files locally and checked in the changes to your local repository, you'll need to occasionally pull down any changes that others have made upstream.  You do this with a ''pull''.  The --rebase option means rather than treat your development as a parallel set, try and apply your resulting patches to the end of the pulled branch instead of merging them.  This tends to keep a cleaner history tree.
  
   # git pull origin master
+
   # git pull --rebase origin master
  
 
Assuming you followed the instructions above, and didn't cloning from somewhere else first, you should be able to shorten this to:
 
Assuming you followed the instructions above, and didn't cloning from somewhere else first, you should be able to shorten this to:
  
   # git pull
+
   # git pull --rebase
  
 
This will merge any changes you've made with any that others have made.  If something goes wrong, git will complain about conflicts and you'll need to resolve those either manually or using ''git mergetool''.  That's a longer subject for another lesson: [[Git Merging]].
 
This will merge any changes you've made with any that others have made.  If something goes wrong, git will complain about conflicts and you'll need to resolve those either manually or using ''git mergetool''.  That's a longer subject for another lesson: [[Git Merging]].

Revision as of 00:23, 28 June 2011

Git is a distributed version control system. This page provides information for developers on how we manage our sources within git.

Setup

 git clone ssh://USERNAME@net-snmp.git.sourceforge.net/gitroot/net-snmp/MODULE

Make sure your email address and name are correct:

 git config user.email "YOURSFACCOUNTNAME@users.sourceforge.net"
 git config user.name "YOUR NAME"

Git work flows

The first link below should be read before any code is checked in. Specifically, it describes the one important aspect: always commit to the lowest branch you want the patch to apply to!

Making changes

This is where you type vi or emacs or if you're a real developer who likes to get dirty perl -i -p -e ...

Committing the changes

 git commit -m "commit message" FILES

Or if you want to commit everything in a directory and down, use a directory name instead of FILES.

Or if you want to commit everything anywhere in the repo, use the -a switch.

NOTE: this only commits them to your local copy of the repository. This is different than SVN, if you're more familiar with SVN. Next you need to push them to the master repository:

Pulling the latest changes from the upstream

Whether or not you've modified files locally and checked in the changes to your local repository, you'll need to occasionally pull down any changes that others have made upstream. You do this with a pull. The --rebase option means rather than treat your development as a parallel set, try and apply your resulting patches to the end of the pulled branch instead of merging them. This tends to keep a cleaner history tree.

 # git pull --rebase origin master

Assuming you followed the instructions above, and didn't cloning from somewhere else first, you should be able to shorten this to:

 # git pull --rebase

This will merge any changes you've made with any that others have made. If something goes wrong, git will complain about conflicts and you'll need to resolve those either manually or using git mergetool. That's a longer subject for another lesson: Git Merging.

You may also wish to pull all the remote branches:

 # git pull --all

Pushing the changes upstream

Once you're sure your commits are safe themselves and you've updated your repo with the latest upstream you can push your changes upstream to the master repository on sourceforge:

 # git push origin master

Assuming you followed the instructions above, and didn't cloning from somewhere else first, you should be able to shorten this to:

 # git push

And you're done!

Notes on the htdocs repository

The htdocs module, which contains the Net-SNMP website, is only synchronized from the git repository once an hour. It may take up to an hour before the changes take effect on the website.

Creating tags and branches

Tagging

Tags are simply a symbolic way of remembering "a point in time" that is easier than the sha1 hash that is more frequently seen.

 git tag my-really-super-feature-works

for example will create the above tag.

XXX: discuss annotated/signed/etc tags

Pushing tags

By default, git push doesn't push tags. IE, it *only* pushes code. If you've created a tag and you want it pushed upstream, you'll need to push it manually:

 git push origin TAGNAME

Or you can push all your tags:

 git push --tags

Note: Please don't push personal tags... Use the individual push instead if you're creating helpful personal tags.