Basic Concepts
- Working Directory
- Staging Area (.git/index)
- .git directory
Useful Commands
Configuration files
Repository config file: .git/config
System config file: ~/.gitconfig
.git\config 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
worktree = C:/git/myrepo
ignorecase = true
[submodule]
active = .
[remote "origin"]
url = https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/myrepo
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "release/prod"]
remote = origin
merge = refs/heads/release/prod
remote = origin
merge = refs/heads/release/preprod
[branch "release/test"]
remote = origin
merge = refs/heads/release/test
[branch "release/dev"]
remote = origin
merge = refs/heads/release/dev
git remote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32$ git remote show
origin
$ git remote -v
origin https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/myrepo (fetch)
origin https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/myrepo (push)
$ git remote show origin
* remote origin
Fetch URL: https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/myrepo
Push URL: https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/myrepo
HEAD branch: master
Remote branches:
develop tracked
feature/test tracked
master tracked
release/dev tracked
release/preprod tracked
release/prod tracked
release/test tracked
Local branches configured for 'git pull':
master merges with remote master
release/dev merges with remote release/dev
release/preprod merges with remote release/preprod
release/prod merges with remote release/prod
release/test merges with remote release/test
Local refs configured for 'git push':
master pushes to master (up to date)
release/dev pushes to release/dev (up to date)
release/preprod pushes to release/preprod (up to date)
release/prod pushes to release/prod (up to date)
release/test pushes to release/test (up to date)git push [repository] [refspec]
1
2
3
4
5$ git status
On branch release/preprod
$ git push
Everything up-to-dategit rebase (current branch is topic)
A---B---C topic* / D---E---F---G master git rebase master git rebase master topic A'--B'--C' topic* / D---E---F---G master
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ git log --oneline
c60c0d9 (HEAD -> release/dev, origin/release/dev) Upgrade node version
16675e8 Update oracledb version
e5461ba Update oracledb version
4e70188 Change Nodejs version to 14
52cf369 Add GEO IP City Function
52cf369 -- 4e70188 -- e5461ba -- 16675e8 -- c60c0d9
Squash 4e70188 -- e5461ba -- 16675e8 -- c60c0d9 into one commit
$ git rebase -i 52cf369
pick 4e70188 Change Nodejs version to 14
squash e5461ba Update oracledb version # meld into previous commit
squash 16675e8 Update oracledb version # meld into previous commit
squash c60c0d9 Upgrade node versiong # meld into previous commit
52cf369 -- d59392d
$ git log --oneline
d59392d Update Nodejs version to 14 and oracledb version
52cf369 Add GEO IP City Function
git merge (current branch is master)
A---B---C topic / D---E---F---G master* git merge topic A---B---C topic / \ D---E---F---G---H master*
1
2
3
4
5# Merge topic with current branch
$ git merge topic
Updating ea2980a..532a0fa
Fast-forward
README.md | 2 +-git pull
git fetch
followed bygit merge
orgit rebase
(with --rebase)FETCH_HEAD is a short-lived ref, to keep track of what has just been fetched from the remote repository
A---B---C master on origin / D---E---F---G master* ^ origin/master in your repository A---B---C origin/master / \ D---E---F---G---H master
git fetch
git fetch --all
Fetch all remote branchesgit fetch origin master
Fetch only remote master branchgit commit
Record changes to the repository-a
Automatically stage modified and deleted files but new files are not affected (usegit add
for new files)git add
Add file contents to the staging area(index)git checkout
Switch branches or restore working tree filesgit checkout [<branch>]
-b
- create a new branch-B
- create a new branch or reset the branchgit show
Shows one or more objects (blobs, trees, tags and commits).git log
--oneline
ancestry references
^
: the parent of that commit^2
: the second parent of that commit (from the branch that was merged (say, topic))~
: first parent~2
: first parent of first parent (it traverses the first parents the number of times you specify)~~
: first parent of first parent