Git
Setting up a repository on the server
# mkdir /srv/git/projectname.git
# git --bare init /srv/git/projectname.git
# chown -R git:git /srv/git/projectname.git
$ git config --global --add safe.directory /srv/git/poopsheet.git
git pull --rebase
git rebase --abort
Learning git
git help
git help tutorial
git help everyday
git help revisions
git help workflows
configuration
Default .git/conf
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = /srv/git/myprojectname.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Assume the following history exists and the current branch is master:
Glossary
- commit message
- current branch
- CVS
- Concurrent Versions System, a style which can be addopted by git if pull and fetch are used.
- graduation
- from next or seen to master to maint
- integration branch
- maint
- tracks the commits that should go into the next "maintenance release"
- master
- A feature release is created from the master branch, since master tracks the commits that should go into the next feature release. The master branch is supposed to be a superset of maint.
- merge
- next
- origin
- remote refs
- seen
- shared repository
- tag
- eg v2.43
- topic branch
- upstream
Workflow
git help workflows
Separate Changes
Try to split your work into small steps from the very beginning. It is always easier to squash a few commits together than to split one big commit into several. Don’t be afraid of making too small or imperfect steps along the way. You can always go back later and edit the commits with
git rebase --interactive
before you publish them. You can usegit stash push --keep-index
to run the test suite independent of other uncommitted changes; see the EXAMPLES section of git-stash.
Example 1. Merge upwards
Example 2. Topic branches
Example 3. Merge to downstream only at well-defined points
Example 4. Throw-away integration branches
Example 5. Verify master is a superset of maint
Example 6. Release tagging
Example 7. Copy maint
Example 8. Update maint to new release
Example 9. Rewind and rebuild next
Example 10. Push/pull: Publishing branches/topics
Example 11. Push/pull: Staying up to date
Example 12. Push/pull: Merging remote topics
Example 13. format-patch/am: Publishing branches/topics
Example 14. format-patch/am: Keeping topics up to date
Example 15. format-patch/am: Importing patches
git help
Three equivalent ways to get the man pages
git help <verb>
git <verb> --help
man git-<verb>
More concise help is available from
git <verb> -h
git help
produces the following template to build notes from:
start a working area (see also: git help tutorial)
clone
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index mv Move or rename a file, a directory, or a symlink restore Restore working tree files rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug diff Show changes between commits, commit and working tree, etc grep Print lines matching a pattern log Show commit logs
show
Show various types of objects
git show-branch
[master] a few edits
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit
Record changes to the repository
How to Write Better Git Commit Messages – A Step-By-Step Guide
merge
Join two or more development histories together
rebase
Reapply commits on top of another base tip
reset
Reset current HEAD to the specified state
switch
Switch branches
tag
Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push
Update remote refs along with associated objects
Individual Developer (Standalone) commands
Described in git help everyday
.
- init
- log
- switch
- add
- diff
- status
- commit
- restore
- merge
- rebase
- tag
Individual Developer (Participant) commands
Described in git help everyday
.
- clone
- pull
- fetch
- push
- format-patch
- send-email
- request-pull
Integrator
Described in git help everyday
.
- am
- pull
- format-patch
- revert
- push
Repository Administrator
- daemon
- shell
- http-backend
- gitweb
tutorial or git help tutorial
Creating Repositories with init or clone
git init
Start a new Git repository for an existing code base
cd /path/to/my/codebase
git init
git add .
git commit
Create an empty Git repository or reinitialize an existing one
mkdir /srv/git/projectname.git
git --bare init /srv/git/projectname.git
chown -R git:git /srv/git/projectname.git
The output of git --bare init /srv/git/projectname.git
is:
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
git clone
Clone a repository into a new directory
The clone command creates a new directory named after the project. After you cd into this directory, you will see that it contains a copy of the project files, called the working tree, together with a special top-level directory named .git, which contains all the information about the history of the project.
Branches
A freshly cloned repository contains a single branch head, by default named “master”, with the working directory initialized to the state of the project referred to by that branch head.
git branch
git branch
* master
git switch
Switch branches
Creating a new branch
git switch [<options>] (-c|-C) <new-branch> [<start-point>]
git switch -c new v2.6.13
git branch
master
* new
Tags
git tag
Create, list, delete or verify a tag object signed with GPG
Tags are expected to always point at the same version of a project, while heads are expected to advance as development progresses.
First attempt at using this failed:
git tag v0.1
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
This works
git tag -f "v0.01"
git reset
Reset current HEAD to the specified state
git add
git add --help
or
git help add
Add file contents to the index
Understanding History
git commit
git commit -m 'Initial commit'
git add forgotten_file
git commit --amend
Record changes to the repository
git show
Show various types of objects
git log
Show commit logs
git remote
Manage set of tracked repositories
Local Protocol
git remote add local_proj /srv/git/project.git
git clone /srv/git/project.git
I’ve been doing it with file://… which I subsequently discovered is slower and unnecessary.
Remote Protocol
git remote add origin ssh://git@example.com:22/srv/git/project.git
git push
Update remote refs along with associated objects
git rm
git checkout
Switch branches or restore working tree files
git reset
Reset current HEAD to the specified state
git reset --help
git restore
Restore working tree files
Server
https://stackoverflow.com/questions/1558719/using-a-remote-repository-with-non-standard-port
https://wiki.archlinux.org/title/Git_server
https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols
https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
Development PC
Step 1, need to run git init
.
git remote add origin ssh://git@example.com:22/srv/git/myreponame.git
git push origin master
to clone from the server to the client:
git clone ssh://git@example.com:22/srv/git/joeblog.git
git clone file:///srv/git/joeblog.git
git add
use -a with git commit ...
instead.
Only files added with add are tracked.
git status
git diff
Using Git to Publish Files
https://www.inmotionhosting.com/support/website/git/git-server/
Need to setup a ~/.ssh/config file
Host my_git_host
HostName git.some.host.org
Port 24589
User not_a_root_user
git via ssh
/etc/passwd
git:x:973:973:git daemon user:/srv/git:/usr/bin/git-shell
less /usr/lib/systemd/system/git-daemon@.service
[Unit]
Description=Git Daemon Instance
[Service]
User=git
# The '-' is to ignore non-zero exit statuses
ExecStart=-/usr/lib/git-core/git-daemon --inetd --export-all --base-path=/srv/git –enable=receive-pack
StandardInput=socket
StandardOutput=inherit
StandardError=journal
ProtectSystem=full
ProtectHome=on
PrivateDevices=on
NoNewPrivileges=on
chage -E -1 git