Development using git: Difference between revisions

From Alpine Linux
(→‎References: Link to git_with_write_access)
No edit summary
 
(40 intermediate revisions by 13 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 [https://git-scm.com git] for Alpine Linux development and related projects. If you just want to browse the Alpine git repositories, please visit [https://git.alpinelinux.org/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 <nowiki>http://proxy_ip:proxy_port</nowiki>}}
}}


Make your changes.
== Cloning a repository via Git ==


To prepare a patch:
There are two ways to work with the Alpine git repository...


git diff &gt; short-description-of-change.patch
* ...without write access.
* ...with write access.


This diff can be sent to [mailto:alpine-devel@lists.alpinelinux.org alpine-devel@lists.alpinelinux.org] mailing list.
[https://git.alpinelinux.org/aports git.alpinelinux.org] shows all available Alpine git repositories.


== Create new git repository for a new project ==
=== Without write access ===
Start with creating a new directory. In this example the project will be named myproj.


  mkdir myproj
If you want to clone the Alpine aports repository, switch to the directory you want to have the ''aports/'' directory in and launch git.
cd myproj
   
{{Cmd|git clone <nowiki>git://git.alpinelinux.org/aports.git</nowiki>}}


Lets initialize the git repository. This will create the .git dir.
{{Tip| If you are using proxy server:
git init
{{Cmd|git clone https://git.alpinelinux.org/aports}}
}}


Now create the initial files you want. In this example we just create hello.txt
If you want only the last 3 revisions:
echo "hello git" > hello.txt


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.
{{Cmd|git clone <nowiki>git://git.alpinelinux.org/aports.git</nowiki> --depth 3}}
git add hello.txt
git commit -v


The format of the commit message should be:
Use the command below to see the full log of the trunk.  
[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.
{{Cmd|git log}}


Now you can see the initial commit with:
=== Submitting work without write access ===
git log


Make some more changes. In this example we just append some text to hello.txt
You can still [https://wiki.alpinelinux.org/wiki/Creating_patches submit a patch] without write access to the Alpine repository. For this you need to create an account on Alpine's GitLab, fork the desired repository (the fork resides on the server), clone the fork on your computer, make your changes into a separate branch, push the squashed branch to the fork (as branch; do not merge/rebase it into the master!) and create a merge request for that branch through the GitLab Web GUI.
echo "hello again" >> hello.txt


To check what you have done since last commit use:
=== With write access ===
git log


To commit the change do:
If you have write access to the Alpine repository, the URL needs to be adjusted for cloning a repository
git add hello.txt
git commit -v


or alternatively:
{{Cmd|git clone git@git.alpinelinux.org:aports}}
git commit -a -v


The separate ''git add'' is useful when you ave changed many files but just want commit some of the changed files.
Alternatively you can set the remote url of an exisiting git clone:
{{Cmd|git remote set-url origin git@git.alpinelinux.org:aports}}


== Publish the new repo to git.alpinelinux.org ==
== General GIT Workflow ==
make a 'bare' copy of your git repository.
# Make your file edits in your local checkout of the local copy of repository.
cd ..
# Commit the changes in your local repository: {{Cmd|git commit}}
git clone --bare myproj myrepo.git
# 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.


Copy that to git.alpinelinux.org. You need an ssh account for this.
== Other related articles ==
scp -r myproj.git git.alpinelinux.org:


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.
* [[Development_using_git:Basic_usage| Basic usage]]
* [[Package Maintainers]]
* [[Creating patches]]
* [[Development_using_git:Developer_repositories|Developer repositories]]
* [[Development_using_git:Cgit| Using Cgit]]
* [[Development using git:Quality assurance]]
* [[Gitolite]]


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.
== Further reading ==
mv myproj myproj.backup
{{:Development_using_git:Documentation}}
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:
[[Category:Development]]
git push
[[Category:Git]]
 
 
 
== 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 &lt;ncopa@example.com&gt;" &gt; 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  ==
If you are a developer with ssh access (with permissions) you might want to take a look at these docs:
*[[Development_using_git_with_write_access]]
 
Some other 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 06:47, 23 August 2023

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

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 https://git.alpinelinux.org/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

Submitting work without write access

You can still submit a patch without write access to the Alpine repository. For this you need to create an account on Alpine's GitLab, fork the desired repository (the fork resides on the server), clone the fork on your computer, make your changes into a separate branch, push the squashed branch to the fork (as branch; do not merge/rebase it into the master!) and create a merge request for that branch through the GitLab Web GUI.

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