Difference between revisions of "Git"
m (→.gitignore file) |
m |
||
Line 1: | Line 1: | ||
+ | =What is git= | ||
+ | Git is a is a distributed version control system: tracking changes in any set of files, usually used for coordinating work among programmers. | ||
+ | [[Image:Git-basic.png|400px|thumb|center|Basic flow of files in git]] | ||
+ | {|border=1 ;style="margin: 0 auto; text-align: center;cellpadding="5" cellspacing="0" | ||
+ | |- bgcolor=lightgrey | ||
+ | !Area!!Explanation | ||
+ | |- | ||
+ | |Working directory|| Typically the project homefolder | ||
+ | |- | ||
+ | |Staging area|| Files "staged" to go into your next commit with the '''git add''' command | ||
+ | |- | ||
+ | |Repository|| The database and history of committed project files. '''git commit''' command | ||
+ | |- | ||
+ | |} | ||
=Install git= | =Install git= | ||
Download git from https://git-scm.com/download/win and install it. | Download git from https://git-scm.com/download/win and install it. | ||
Learn basic git by watching this video tutorial: [https://learning.oreilly.com/videos/-/9781789348231/ Learn git in 3 hours] | Learn basic git by watching this video tutorial: [https://learning.oreilly.com/videos/-/9781789348231/ Learn git in 3 hours] | ||
− | + | { | |
=Basic configuration= | =Basic configuration= | ||
From terminal issue the following commands: (Windows start the '''git bash''' app) | From terminal issue the following commands: (Windows start the '''git bash''' app) |
Revision as of 06:56, 22 December 2022
Contents
What is git
Git is a is a distributed version control system: tracking changes in any set of files, usually used for coordinating work among programmers.
Area | Explanation |
---|---|
Working directory | Typically the project homefolder |
Staging area | Files "staged" to go into your next commit with the git add command |
Repository | The database and history of committed project files. git commit command |
Install git
Download git from https://git-scm.com/download/win and install it.
Learn basic git by watching this video tutorial: Learn git in 3 hours {
Basic configuration
From terminal issue the following commands: (Windows start the git bash app)
git config --global user.name "Henrik Thomsen"
git config --global user.email "heth@mercantec.dk"
It will create a ~/.gitconfig file for the user
Create a new git project
mkdir project
cd project
git init
git init will create a .git directory
File tracking states
A specified file can be in one of four states
State | Explanation |
---|---|
Untracked | The file is not tracked by git and changes are not recorded |
Unmodified | The file is tracked by git and has not changed since it's last commit |
Modified | The file is tracked by git and has changed since it's last commit |
Staged | means that you have marked a modified file in its current version to go into your next commit snapshot. |
File tracking lifecycle
Basic git commands
command | Explanation |
---|---|
git status | Status of git repository (must be inproject or project subfolder) |
git add <file/dir>... | Files added to the repository - Untracked->staged or Modified->staged
Note: When adding a directory - the directory is not tracked for new files |
git diff [file...] | See modified files content - files not staged (Use git add to stage) |
git diff --staged [file...] | See staged files modified but not committed |
git commit | Interactive: Commit staged files to repository - Write a comment in the editor and exit |
git commit -v | Same as above, but shows you the differences |
git commit -m TXT | Commits directly with the commit TXT |
git commit -a -m TXT | add all changed files to the staging area and commit |
.gitignore file
To ignore fx. build files or logfiles create a .gitignore file in the repository home directory. Content fx. *.log Pattern matching
- Asterisk matches zero or more characters *
- Patterns starting with a slash / matches in the same name as the .gitignore file
- Patterns ending with a slash / only match folder names
- Exclamation mark ! negates a pattern: fx. !henrik.log includes henrik.log even if *.log is ignored
- Nested directories: /**/*.c Will include all *.c files regardless of number if subdirectories
- See: https://github.com/github/gitignore for examples of .gitignore project files
Why is it called Git?
Linus Torvalds has quipped about the name "git", which is British English slang for a stupid or unpleasant person. Torvalds said: "I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'."[1][2][3]