2.6 KiB
obj |
---|
application |
Git
#refactor
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.
There is a commit naming scheme called gitmoji
To control a git repo graphically GitHub Desktop can be used.
Configuration
In order to use Git you need to set at least a name and email:
git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com"
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.
Using a Git repository
Initialize a repository
git init
Clone an existing repository
git clone repository
Commit:
git commit -m message
See Commits:
git log
See structured history:
git log --graph --oneline --decorate
Signing commits
Git allows commits and tags to be signed using GnuPG.
git config --global commit.gpgSign true
Branching
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:
git branch help-section-addition
List branches:
git branch
Switch branches:
git checkout branch
Create and switch:
git checkout -b branch
Merge a branch back to the master branch:
git checkout master
git merge 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.
When done with a branch, delete it with:
git branch -d branch
Remotes
Create a remote:
git remote add label location
View remotes for the current repository:
git remote -v
Pull from a reposity:
git pull
Push to a repository:
git push location branch
Tagging
Tag commits for versioning:
git tag 2.14 checksum
git tag -a 2.14 -m "Version 2.14"
List tags:
git tag -l
Delete a tag:
git tag -d 2.08
Update remote tags:
git push --tags