Difference between revisions of "Development using git"

From Alpine Linux
Jump to: navigation, search
(added note on how to submit a new proj to git.a.o)
(With write access)
 
(34 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[http://git.or.cz Git] is now being used for version control of the [http://dev.alpinelinux.org/cgit/cgit.cgi/alpine-baselayout/ alpine-baselayout] and [http://dev.alpinelinux.org/cgit/cgit.cgi/alpine-conf alpine-conf] packages.
+
{{Move|Git|All git development articles should be consolidated}}
  
== Configuring git ==
+
This document describes how to use [http://git-scm.com git] for Alpine Linux development and related projects. If you just want to browse the Alpine git repositories, please visit [http://git.alpinelinux.org/cgit/aports git.alpinelinux.org].
First you need to tell your name and email to git. This name and email will show up in all your commits.
 
  
git config --global user.name "Your Name Comes Here"
+
== Basic Git usage ==
git config --global user.email you@yourdomain.example.com
 
  
== Git Clone  ==
+
{{:Development_using_git:Configuration}}
  
To get started, clone the [http://dev.alpinelinux.org/cgit git repository] for the package you are interested in:
+
{{Tip| If you want to use git with colored output use:
 +
{{Cmd|git config --global color.ui true
 +
git config --global core.pager more}}
 +
}}
  
  git clone git://git.alpinelinux.org/alpine-baselayout
+
{{Tip| If you want to use git with proxy server:
  git clone git://git.alpinelinux.org/alpine-conf
+
{{Cmd|git config --global http.proxy http://proxy_ip:proxy_port}}
 +
}}
  
Make your changes.
+
{{:Development_using_git:Email}}
  
To prepare a patch:
+
== Cloning a repository via Git ==
  
git diff > short-description-of-change.patch
+
There are two ways to work with the Alpine git repository...
  
This diff can be sent to [mailto:alpine-devel@lists.alpinelinux.org alpine-devel@lists.alpinelinux.org] mailing list.
+
* ...without write access.
 +
* ...with write access.
  
== Create new git repository for a new project ==
+
[http://git.alpinelinux.org/cgit/aports git.alpinelinux.org] shows all available Alpine git repositories.
Start with creating a new directory. In this example the project will be named myproj.
 
  
mkdir myproj
+
=== Without write access ===
cd myproj
 
  
Lets initialize the git repository. This will create the .git dir.
+
If you want to clone the Alpine aports repository, switch to the directory you want to have the ''aports/'' directory in and launch git.
  git init
+
   
 +
{{Cmd|git clone git://git.alpinelinux.org/aports.git}}
  
Now create the initial files you want. In this example we just create hello.txt
+
{{Tip| If you are using proxy server:
  echo "hello git" > hello.txt
+
  {{Cmd|git clone http://git.alpinelinux.org/cgit/aports}}
 +
}}
  
We add this to the git "index" and commit it. The -v option shows the diff as a last reiew. Your $EDITOR will be opened and you will need to create a description of the initial commit.
+
If you want only the last 3 revisions:
git add hello.txt
 
git commit -v
 
  
The format of the commit message should be:
+
{{Cmd|git clone git://git.alpinelinux.org/aports.git --depth 3}}
[first line]One-line descrption thats les than 72 chars long
 
[second line empty]
 
[third line]longer description.
 
  
Think of first line as the subject in an email and the third line and on as the body of the email, describing what the commit does. You dont need the long description but the first line, the short description should be there as it will be showed in the commit log.
+
Use the command below to see the full log of the trunk.  
  
Now you can see the initial commit with:
+
{{Cmd|git log}}
git log
 
  
Make some more changes. In this example we just append some text to hello.txt
+
=== With write access ===
echo "hello again" >> hello.txt
 
  
To check what you have done since last commit use:
+
If you have write access to the Alpine repository, the URL needs to be adjusted for cloning a repository
git log
 
  
To commit the change do:
+
{{Cmd|git clone git@git.alpinelinux.org:aports}}
git add hello.txt
 
git commit -v
 
  
or alternatively:
+
Alternatively you can set the remote url of an exisiting git clone:
git commit -a -v
+
{{Cmd|git remote set-url origin git@git.alpinelinux.org:aports}}
  
The separate ''git add'' is useful when you ave changed many files but just want commit some of the changed files.
+
== General GIT Workflow ==
 +
# Make your file edits in your local checkout of the local copy of repository.
 +
# Commit the changes in your local repository: {{Cmd|git commit}}
 +
# Bring the rest of your local repository up to date: {{Cmd|git pull --rebase}}
 +
# Check what you are going to push: {{Cmd|git log origin..master}}
 +
# Move your changes up to the master if you have write access {{Cmd|git push}} or [[Creating_patches|create a patch]] if not.
  
== Publish the new repo to git.alpinelinux.org ==
+
== Other related articles ==
make a 'bare' copy of your git repository.
 
cd ..
 
git clone --bare myproj myrepo.git
 
  
Copy that to git.alpinelinux.org. You need an ssh account for this.
+
* [[Development_using_git:Basic_usage| Basic usage]]
scp -r myproj.git git.alpinelinux.org:
+
* [[Package Maintainers]]
 +
* [[Creating patches]]
 +
* [[Development_using_git:Developer_repositories|Developer repositories]]
 +
* [[Development_using_git:Cgit| Using Cgit]]
 +
* [[Development using git:Quality assurance]]
 +
* [[Gitolite]]
  
Send an email to Natanael Copa (or ping him on irc) to make a symlink of it to /gitroot on and to make it visible from cgit.
+
== Further reading ==
 +
{{:Development_using_git:Documentation}}
  
Now you can clone the remote repository from git.alpinelinux.org. First you have to remove the old ''myproj'' directory. Then you clone it with ssh.
+
[[Category:Development]]
mv myproj myproj.backup
+
[[Category:Git]]
git clone ssh://git.alpinelinux.org/~/myproj.git
 
 
 
Now you have a local copy of the remote repository in ''myproj/'' directory. You can make changes there as much as you want. You can make commits, tags, undo/redo commits/tags (thats not pushed). You can do that without even having internet access. When you want to submit your changes (all you commits since last ''pull'') you do:
 
git push
 
 
 
 
 
 
 
== Migrate a subversion repository to git  ==
 
 
 
Start with creating a users.txt file where the svn users are mapped to an email address for git.
 
 
 
echo "ncopa = Natanael Copa <ncopa@example.com>" > users.txt
 
 
 
Create a temp work area.
 
 
 
mkdir proj-tmp
 
 
 
Init the git repository. If your svn repo does not have the standard trunk branches and tags dirs you shouldnt use the --stdlayout. You can also use -T trunk -b branches -t tags.
 
 
 
cd proj-tmp
 
git svn init svn://svn.alpinelinux.org/proj --stdlayout
 
 
 
Connect the users.txt to the empty git repository so users are remapped.
 
 
 
git config svn.authorsfile ../users.txt
 
 
 
Fetch and import the svn repository. This might take some time.
 
 
 
git fetch
 
 
 
Now we can create a bare repository and upload it to dev.alpinelinux.org/gitroot.
 
 
 
cd ..
 
git clone --bare proj-tmp proj.git
 
scp -r proj.git dev.alpinelinux.org:/gitroot
 
 
 
== References  ==
 
 
 
Some useful documents
 
 
 
*[http://git.or.cz/course/svn.html Git - SVN Crash Course] (quickstart if you know svn)
 
*[http://cworth.org/hgbook-git/tour/ A tour of git: the basics] '''Recommended'''
 
*[http://book.git-scm.com/ The Git Community Book]
 

Latest revision as of 15:02, 30 April 2019

Tango-go-next.png
This page is proposed for moving ...

It should be renamed to Git. All git development articles should be consolidated (Discuss)

This document describes how to use git for Alpine Linux development and related projects. If you just want to browse the Alpine git repositories, please visit git.alpinelinux.org.

Basic Git usage

Configure your global git config

First you need to tell your name and email to git. This name and email will show up in all your commits.

git config --global user.name "Your Name Comes Here" git config --global user.email you@yourdomain.example.com

Using git config without --global let you configure other details for a specific git repository.

Tip: If you want to use git with colored output use:

git config --global color.ui true git config --global core.pager more

Tip: If you want to use git with proxy server:

git config --global http.proxy http://proxy_ip:proxy_port

Email configuration

To be able send your commits (patches) via email you need configure an SMTP server.

git config --global sendemail.smtpserver smtp.exmaple.com

For sending from a gmail address you can do:

git config --global sendemail.smtpserver smtp.gmail.com git config --global sendemail.smtpserverport 587 git config --global sendemail.smtpencryption tls git config --global sendemail.smtpuser your_email@gmail.com

Optionally, it is possible to skip the password prompt by adding it to the configuration with:

git config --global sendemail.smtppass your_password

To reset CC mail attribute

git config --global sendemail.suppresscc all


Example ~/.gitconfig

[user]
        email = user@gmail.com
        name = Your Name
[core]
        editor = nano
        pager = less -FXRS
[sendemail]
        from = Your Name <user@gmail.com>
        smtpuser = user@gmail.com
	smtpserver = smtp.googlemail.com
	smtpencryption = tls
	smtpserverport = 587
	suppresscc = self

[push]
        default = simple

Cloning a repository via Git

There are two ways to work with the Alpine git repository...

  • ...without write access.
  • ...with write access.

git.alpinelinux.org shows all available Alpine git repositories.

Without write access

If you want to clone the Alpine aports repository, switch to the directory you want to have the aports/ directory in and launch git.

git clone git://git.alpinelinux.org/aports.git

Tip: If you are using proxy server:

git clone http://git.alpinelinux.org/cgit/aports

If you want only the last 3 revisions:

git clone git://git.alpinelinux.org/aports.git --depth 3

Use the command below to see the full log of the trunk.

git log

With write access

If you have write access to the Alpine repository, the URL needs to be adjusted for cloning a repository

git clone git@git.alpinelinux.org:aports

Alternatively you can set the remote url of an exisiting git clone:

git remote set-url origin git@git.alpinelinux.org:aports

General GIT Workflow

  1. Make your file edits in your local checkout of the local copy of repository.
  2. Commit the changes in your local repository:

    git commit

  3. Bring the rest of your local repository up to date:

    git pull --rebase

  4. Check what you are going to push:

    git log origin..master

  5. Move your changes up to the master if you have write access

    git push

    or create a patch if not.

Other related articles

Further reading