Git: Difference between revisions
Prabuanand (talk | contribs) (added reference to quality assurance hook) |
Prabuanand (talk | contribs) (Reformatted headings, removed old references) |
||
Line 60: | Line 60: | ||
# Check what you are going to push: {{Cmd|git log origin..master}} | # 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. | # Move your changes up to the master if you have write access {{Cmd|git push}} or [[Creating_patches|create a patch]] if not. | ||
== Quality assurance == | |||
{{:Development using git:Quality assurance}} | |||
== Git Basics == | |||
{{:Include:Git Basics|}} | |||
== Other related articles == | == Other related articles == | ||
* [[Package Maintainers]] | * [[Package Maintainers]] | ||
* [[Creating patches]] | * [[Creating patches]] | ||
* [[Development_using_git:Developer_repositories|Developer repositories]] | * [[Development_using_git:Developer_repositories|Developer repositories]] | ||
* [[Development_using_git:Cgit| Using Cgit]] | * [[Development_using_git:Cgit| Using Cgit]] | ||
* [[Gitolite]] | * [[Gitolite]] | ||
Revision as of 09:54, 14 August 2024
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. If you are new to git and need quick reference, check Git Basics
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.
git config --global color.ui true git config --global core.pager more
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
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
- Make your file edits in your local checkout of the local copy of repository.
- Ensure that your commits meets the Quality assurance
- Commit the changes in your local repository:
git commit
- Bring the rest of your local repository up to date:
git pull --rebase
- Check what you are going to push:
git log origin..master
- Move your changes up to the master if you have write access
git push
or create a patch if not.
Quality assurance
Before pushing anything to it is good to make sure that:
- The package actually builds
- Commit message is good
- pkgrel is bumped if needed
- no whitespace damage (last chars of a line is whitespace)
The following git hook will help you catch some common errors early:
#!/bin/sh # Redirect output to stderr. exec 1>&2 git diff --cached --name-only HEAD | grep 'APKBUILD$' | while read f; do olddir=$PWD cd ${f%/APKBUILD} if ! abuild sanitycheck && verify; then exit 1 fi cd "$olddir" done # If there are whitespace errors, print the offending file names and fail. exec git diff-index --check --cached HEAD --
Install it as .git/hooks/pre-commit and make it executable.
Git Basics
Stashing
git stash
if you want to "hide" your changes. Do this if you think there may be other commits against the same things you are working on and want to refresh your local checkout (using a git pull --rebase) from the master. Use git stash apply to get your stash back.
Reset your local repository
git checkout -f master
if you think your tree is pretty hopeless, need a kill-and-fill to bring the master into your local repository. You will lose local changes.
List the local branch
You can now list your local branch by doing
git branch
which should ouput
* master
List your local non committed changes
git status
Commit
Now you can start to work on your tree. As soon as you feel you have reached a step in development where you can commit your work locally, use
git commit -a
or
git commit <specific files>
or
git add <specific files> git commit
If you wish to give credit to someone else's work (e.g. you are applying a third party patch):
git commit <specific files> --author "Name Surname <user@example.com>
The format of the commit message should be:
One-line description that's less than 72 chars long <second line empty> Optional longer description with explanation why changes were made. Links to relevant issues in Bugtracker can be done with: ref #<issuenumber> It is also possible to resolve issues with: fixes #<issuenumber>
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 don't need the long description but the first line, the short description should be there as it will be showed in the commit log.
autocmd FileType gitcommit set textwidth=72
List your commits
git log
Keeping your local working branch in sync
Pull the changes from upstream (git.alpinelinux.org)
git pull --rebase
Run the command:
git config branch.origin.rebase true
Next time you do 'git pull' you are actually doing a 'git pull --rebase'.Git Tag
Create an annotated tag and push it.
git tag -a tagname -m 'commit message (e.g release 1.x)' git push && git push --tags
Create a new project
Create your own directory that you want to become your new acf-mystuff project.
mkdir acf-mystuff cd acf-mystuff git init
Create your files and add/commit them to your git-project
git add ./ git commit
Further reading
- Git Tutorial
- Git - SVN Crash Course (quickstart if you know svn)
- A tour of git: the basics Recommended
- The Git Community Book
- Git From the Bottom Up
- Very good Git guide