- Git server
- Contents
- Protocols
- General
- Smart HTTP
- Apache
- Access control
- Arch linux install git
- Contents
- Installation
- Graphical front-ends
- Configuration
- Usage
- Getting a Git repository
- Recording changes
- Staging changes
- Committing changes
- Revision selection
- Viewing changes
- Undoing things
- Branching
- Collaboration
- Pull requests
- Using remotes
- Push to a repository
- Dealing with merges
- History and versioning
- Searching the history
- Tagging
- Organizing commits
- Tips and tricks
- Using git-config
- Adopting a good etiquette
- Speeding up authentication
- Using git-credential-libsecret as credential-helper
- Protocol defaults
- Bash completion
- Git prompt
- Visual representation
- Commit tips
- Signing commits
- Working with a non-master branch
- Directly sending patches to a mailing list
- When the remote repo is huge
- Simplest way: fetch the entire repo
- Partial fetch
- Get other branches
- Possible Future alternative
- Filtering confidential information
- HTML help files
- Extensions
Git server
This article gives an overview on how to host a Git server. For more information, refer to the Git on the Server chapter of the Pro Git book.
Contents
Protocols
Refer to Git on the Server — The Protocols for a detailed description along with pros and cons.
General
Step by Step Guide on Setting Up git Server describes setting up an unsecured server on Arch.
By default, the git user is expired («Your account has expired; please contact your system administrator»). Use chage to remove the expiration condition, e.g. as follows:
You only need to set up an SSH server.
You are able to secure the SSH user account even more allowing only push and pull commands on this user account. This is done by replacing the default login shell by git-shell. Described in Setting Up the Server.
When securing the git server created using the instructions in #General with the instructions of this clause (#SSH), the following additional steps are needed on Arch:
correct home directory In order for ssh to be able to read /srv/git/.ssh/authorized_keys, the home directory for git in /etc/passwd needs to be changed from «/» to «/srv/git». correct base path when home directory is corrected In order for git to serve the repositories, the —base-path in «/usr/lib/systemd/system/git-daemon\@.service» need to be changed to «/srv/git» if the repositories are served from git’s home directory.
Smart HTTP
This article or section needs expansion.
The git-http-backend(1) is a CGI program, allowing efficient cloning, pulling and pushing over HTTP(S).
Apache
The setup for this is rather simple as all you need to have installed is the Apache HTTP Server, with mod_cgi , mod_alias , and mod_env enabled) and of course, git .
Once you have your basic setup running, add the following to your Apache configuration file, which is usually located at:
This assumes your Git repositories are located at /srv/git and that you want to access them via something like: http(s)://your_address.tld/git/your_repo.git .
For more detailed documentation, visit the following links:
The Git protocol is not encrypted or authenticated, and only allows read access.
The Git daemon ( git-daemon(1) ) can be started with git-daemon.socket .
The service uses the —export-all and —base-path parameters to serve all repositories placed in /srv/git/ .
Access control
For fine-grained access control, the following solutions are available:
Note that if you are willing to create user accounts for all of the people that should have access to the repositories and do not need access control at the level of git objects (like branches), you can also use standard file permissions for access control.[1]
Источник
Arch linux install git
Git is the version control system (VCS) designed and developed by Linus Torvalds, the creator of the Linux kernel. Git is now used to maintain AUR packages, as well as many other projects, including sources for the Linux kernel.
Contents
Installation
Install the git package. For the development version, install the git-git AUR package. Check the optional dependencies when using tools such as git svn, git gui and gitk.
Graphical front-ends
- Giggle — GTK frontend for git.
https://wiki.gnome.org/Apps/giggle/ || giggle
- GitAhead — Graphical git client including a built-in Merge Tool.
https://gitahead.github.io/gitahead.com/ || gitaheadAUR
- Git Cola — Sleek and powerful graphical user interface for Git written in Python.
https://git-cola.github.io/ || git-colaAUR
- Git Extensions — Graphical user interface for Git that allows you to control Git without using the commandline.
https://gitextensions.github.io/ || gitextensionsAUR
- gitg — GNOME GUI client to view git repositories.
https://wiki.gnome.org/Apps/Gitg || gitg
- git-gui — Tcl/Tk based portable graphical interface to Git.
https://git-scm.com/docs/git-gui || git + tk
- GitHub Desktop — Electron-based graphical user interface built by the GitHub team.
https://github.com/desktop/desktop || github-desktopAURgithub-desktop-binAUR
- gitk — Tcl/Tk based Git repository browser.
https://git-scm.com/docs/gitk || git + tk
- Guitar — Git GUI Client.
https://github.com/soramimi/Guitar || guitarAUR
- QGit — Git GUI viewer to browse revisions history, view patch content and changed files, graphically following different development branches.
https://github.com/tibirna/qgit || qgit
- RabbitVCS — Set of graphical tools written to provide simple and straightforward access to the version control systems you use.
http://rabbitvcs.org/ || rabbitvcsAUR
- Sublime Merge — Git Client from the makers of Sublime Text.
https://www.sublimemerge.com/ || sublime-mergeAUR
- Tig — ncurses-based text-mode interface for git.
https://jonas.github.io/tig/ || tig
- ungit — Brings user friendliness to git without sacrificing the versatility of git.
https://github.com/FredrikNoren/ungit || nodejs-ungitAUR
Configuration
In order to use Git you need to set at least a name and email:
See #Tips and tricks for more settings.
Usage
A Git repository is contained in a .git directory, which holds the revision history and other metadata. The directory tracked by the repository, by default the parent directory, is called the working directory. Changes in the working tree need to be staged before they can be recorded (committed) to the repository. Git also lets you restore, previously committed, working tree files.
Getting a Git repository
- Initialize a repository
git init , see git-init(1)
- Clone an existing repository
git clone repository , see git-clone(1) (also explains the Git URLs)
Recording changes
Git projects have a staging area, which is an index file in your Git directory, that stores the changes that will go into your next commit. To record a modified file you therefore firstly need to add it to the index (stage it). The git commit command then stores the current index in a new commit.
Staging changes
- Add working tree changes to the index
git add pathspec , see git-add(1)
- Remove changes from the index
git reset pathspec , see git-reset(1)
- Show changes to be committed, unstaged changes and untracked files
git status , see git-status(1)
You can tell Git to ignore certain untracked files using .gitignore files, see gitignore(5) .
Git does not track file movement. Move detection during merges is based only on content similarity. The git mv command is just there for convenience and is equivalent to:
Committing changes
The git commit command records the staged changes to the repository, see git-commit(1) .
- -m – supply the commit message as an argument, instead of composing it in your default text editor
- -a – automatically stage files that have been modified or deleted (does not add untracked files)
- —amend – redo the last commit, amending the commit message or the committed files
Revision selection
Git offers multiple ways to specify revisions, see gitrevisions(7) and Revision Selection.
Many Git commands take revisions as arguments. A commit can be identified by any of the following:
- SHA-1 hash of the commit (the first 7 digits are usually sufficient to identify it uniquely)
- Any commit label such as a branch or tag name
- The label HEAD always refers to the currently checked-out commit (usually the head of the branch, unless you used git checkout to jump back in history to an old commit)
- Any of the above plus
to refer to previous commits. For example, HEAD
refers to one commit before HEAD and HEAD
5 refers to five commits before HEAD .
Viewing changes
Show differences between commits:
or between staging area and working tree:
View history of changes (where «-N» is the number of latest commits):
Undoing things
- git checkout — to restore working tree files, see git-checkout(1)
- git reset — reset current HEAD to the specified state, see git-reset(1)
- git revert — revert some existing commits, see git-revert(1)
These, along with few others, are further explained at undoing-changes.
For more complex modifications of history, such as git commit —amend and git rebase see, for example, rewriting-history. It is highly advised not to use such rewrites for commits that were collaborated with other users. Or, at the very least, highly coordinate it in advance.
Branching
This article or section needs expansion.
Fixes and new features are usually tested in branches. When changes are satisfactory they can merged back into the default (master) branch.
Create a branch, whose name accurately reflects its purpose:
Create and switch:
Merge a branch back to the master branch:
The changes will be merged if they do not conflict. Otherwise, Git will print an error message, and annotate files in the working tree to record the conflicts. The annotations can be displayed with git diff . Conflicts are resolved by editing the files to remove the annotations, and committing the final version. See #Dealing with merges below.
When done with a branch, delete it with:
Collaboration
A typical Git work-flow is:
- Create a new repository or clone a remote one.
- Create a branch to make changes; then commit those changes.
- Consolidate commits for better organization/understanding.
- Merge commits back into the main branch.
- (Optional) Push changes to a remote server.
Pull requests
After making and committing some changes, the contributor can ask the original author to merge them. This is called a pull request.
The pull command combines both fetching and merging. If there are conflicts (e.g. the original author made changes in the same time span), then it will be necessary to manually fix them.
Alternatively, the original author can pick the changes wanting to be incorporated. Using the fetch option (and log option with a special FETCH_HEAD symbol), the contents of the pull request can be viewed before deciding what to do:
Using remotes
Remotes are aliases for tracked remote repositories. A label is created defining a location. These labels are used to identify frequently accessed repositories.
Create a remote:
Show differences between master and a remote master:
View remotes for the current repository:
When defining a remote that is a parent of the fork (the project lead), it is defined as upstream.
Push to a repository
After being given rights from the original authors, push changes with:
When git clone is performed, it records the original location and gives it a remote name of origin .
So what typically is done is this:
If the -u ( —set-upstream ) option is used, the location is recorded so the next time just a git push is necessary.
Dealing with merges
See Basic Merge Conflicts in the Git Book for a detailed explanation on how to resolve merge conflicts. Merges are generally reversible. If wanting to back out of a merge one can usually use the —abort command (e.g. git merge —abort or git pull —abort ).
History and versioning
Searching the history
git log will give the history with a commit checksum, author, date, and the short message. The checksum is the «object name» of a commit object, typically a 40-character SHA-1 hash.
For history with a long message (where the «checksum» can be truncated, as long as it is unique):
Search for pattern in tracked files:
Search in .c and .h files:
Tagging
Tag commits for versioning:
Tagging is generally done for releasing/versioning but it can be any string. Generally annotated tags are used, because they get added to the Git database.
Tag the current commit with:
Update remote tags:
Organizing commits
Before submitting a pull request it may be desirable to consolidate/organize the commits. This is done with the git rebase —interactive option:
This will open the editor with a summary of all the commits in the range specified; in this case including the newest ( HEAD ) back to, but excluding, commit checksum . Or to use a number notation, use for example HEAD
3 , which will rebase the last three commits:
Editing the action in the first column will dictate how the rebase will be done. The options are:
- pick — Apply this commit as is (the default).
- edit — Edit files and/or commit message.
- reword — Edit commit message.
- squash — Merge/fold into previous commit.
- fixup — Merge/fold into previous commit discarding its message.
The commits can be re-ordered or erased from the history (but be very careful with these). After editing the file, Git will perform the specified actions; if prompted to resolve merge problems, fix them and continue with git rebase —continue or back out with the git rebase —abort command.
Tips and tricks
Using git-config
Git reads its configuration from four INI-type configuration files:
- /etc/gitconfig for system-wide defaults
/.config/git/config (since 1.7.12) for user-specific configuration
These files can be edited directly, but the usual method is to use git config, as shown in the examples below.
List the currently set variables:
Set the default editor from vim to nano:
Set the default push action:
Set a different tool for git difftool (meld by default):
Adopting a good etiquette
- When considering contributing to an existing project, read and understand its license, as it may excessively limit your ability to change the code. Some licenses can generate disputes over the ownership of the code.
- Think about the project’s community and how well you can fit into it. To get a feeling of the direction of the project, read any documentation and even the log of the repository.
- When requesting to pull a commit, or submit a patch, keep it small and well documented; this will help the maintainers understand your changes and decide whether to merge them or ask you to make some amendments.
- If a contribution is rejected, do not get discouraged, it is their project after all. If it is important, discuss the reasoning for the contribution as clearly and as patiently as possible: with such an approach a resolution may eventually be possible.
Speeding up authentication
You may wish to avoid the hassle of authenticating interactively at every push to the Git server.
- If you are authenticating with SSH keys, use an SSH agent. See also OpenSSH#Speeding up SSH and OpenSSH#Keep alive.
- If you are authenticating with username and password, switch to SSH keys if the server supports SSH, otherwise use git-credential-libsecret credential helper, or try git-credential-cache or git-credential-store.
Using git-credential-libsecret as credential-helper
Git may fetch your credentials from a org.freedesktop.secrets compatible keyring like GNOME/Keyring or KeePassXC. Therefore set up one compatible keyring and check if a keyring is registered to dbus using:
Protocol defaults
If you are running a multiplexed SSH connection as shown above, Git over SSH might be faster than HTTPS. Also, some servers (like the AUR) only allow pushing via SSH. For example, the following config will set Git over SSH for any repository hosted on the AUR.
Bash completion
In order to enable Bash completion, source /usr/share/git/completion/git-completion.bash in a Bash startup file. Alternatively, install bash-completion .
Git prompt
The Git package comes with a prompt script. To enable it, source the /usr/share/git/completion/git-prompt.sh and set a custom prompt with the %s parameter:
- For Bash: PS1='[\u@\h \W$(__git_ps1 » (%s)»)]\$ ‘
- For zsh: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 » (%s)»)]\$ ‘
Note that the command substitution must be escaped, see Bash/Prompt customization#Embedding commands for details. See Command-line shell#Configuration files for persistent configuration.
When changing to a directory of a Git repository, the prompt will change to show the branch name. Extra details can be set to be shown by the prompt by setting the corresponding environment variable:
Shell variable | Information |
---|---|
GIT_PS1_SHOWDIRTYSTATE | + for staged, * if unstaged. |
GIT_PS1_SHOWSTASHSTATE | $ if something is stashed. |
GIT_PS1_SHOWUNTRACKEDFILES | % if there are untracked files. |
GIT_PS1_SHOWUPSTREAM | ,<> behind, ahead, or diverged from upstream. |
GIT_PS1_SHOWUPSTREAM will need to be set to auto for changes to take effect.
/.git/config instead of
Alternatively, you can use one of git shell prompt customization packages from AUR such as bash-git-prompt AUR or gittify AUR .
Visual representation
To get an idea of the amount of work done:
git log with forking representation:
git log graph alias (i.e. git graph will show a decorated version):
Commit tips
Reset to previous commit (very dangerous, erases everything to specified commit):
If a repository address gets changed, its remote location will need to be updated:
Alternatively, edit .git/config with the new location.
Signed-off-by line append (a name-email signature is added to the commit which is required by some projects):
Signed-off-by automatically append to patches (when using git format-patch commit ):
Commit specific parts of files that have changed. This is useful if there are a large number of changes made that would be best split into several commits:
Signing commits
Git allows commits and tags to be signed using GnuPG, see Signing Your Work.
To configure Git to automatically sign commits:
Working with a non-master branch
Occasionally a maintainer will ask that work be done on a branch. These branches are often called devel or testing . Begin by cloning the repository.
To enter another branch beside master (git clone only shows master branch but others still exist, git branch -a to show):
Now edit normally; however to keep the repository tree in sync be sure to use both:
Directly sending patches to a mailing list
If you want to send patches directly to a mailing list, you have to install the following packages: perl-authen-sasl and perl-io-socket-ssl .
Make sure you have configured your username and e-mail address, see #Configuration.
Configure your e-mail settings:
Now you should be able to send the patch to the mailing list (see also OpenEmbedded:How to submit a patch to OpenEmbedded#Sending patches and git-send-email.io):
When the remote repo is huge
This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.
When the remote repo is huge, the following solutions can be used. The examples are taken from the linux kernel.
Simplest way: fetch the entire repo
You can get the entire repository by
You can update your repo by git pull .
Partial fetch
Probably you want to limit your local repository smaller, say after v4.14 to bisect a bug. Then do:
Or maybe you only want the latest snapshot, ignoring all history. (If a tarball is available and it suffices, choose that. Getting a git repo costs more.) You can do it by:
You can later obtain older commits, by e.g.
Get other branches
Your local repo tracks, in the above example, only the mainline kernel, i.e. in which the latest development is done. Suppose you want the latest LTS, for example the up-to-date 4.14 branch. You can get it by:
The last line is not mandatory, but probably you want it. (To know the name of the branch you want, sorry, there is no general rule. You can guess one by seeing the «ref» link in the gitweb interface.)
If you want the snapshot of linux-4.17.y, do
Or to extract it in another directory,
As usual, do git pull to update your snapshot.
Possible Future alternative
Git Virtual Filesystem (GVFS), developed by Microsoft, allows you to access git repositories without a local one. (See this Microsoft blog or the Wikipedia article.) It’s not available in Linux yet.
Anyway it is not for the above examples of the Linux kernel, though.
Filtering confidential information
Occasionally, software may keep plain-text passwords in configuration files, as opposed to hooking into a keyring. In these cases, git clean-filters may be handy to avoid accidentally commiting confidential information. E. g., the following file assigns a filter to the file “some-dotfile”:
Whenever the file “some-dotfile” is checked into git, git will invoke the filter “remove-pass” on the file before checking it in. The filter must be defined in the git-configuration file, e. g.:
HTML help files
The git help documentation is also available in HTML form by installing git-htmldocs AUR . After installing, the HTML docs can be accessed by passing the -w flag. For example:
The HTML documentation can be loaded by default by setting a git config option:
Extensions
You can use gitflow to easily manage a repository using Vincent Driessen’s branching model.
Источник