├── README.md
├── docs
├── 01-Git-Course-Introduction
│ └── 01-Git-Course-Introduction.md
├── 02-Git-Introduction
│ ├── 01-Git-Introduction.md
│ ├── 02-Local-and-Remote-Repositories.md
│ ├── 03-Install-Git.md
│ ├── 04-Lab-Introduction.md
│ ├── 05-Practice-Test-Install-Git.md
│ ├── 06-Initialize-a-Git-Repository.md
│ ├── 07-Git-Log.md
│ └── 08-Practice-Test-Git-Log.md
├── 03-Git-Branches
│ ├── 01-Git-Branches.md
│ ├── 02-Practice-Test-Branches.md
│ ├── 03-Git-Merging-Branches.md
│ └── 04-Practice-Test-Merging-Branches.md
├── 04-Initialize-Remote-Repositories
│ ├── 01-Initialize-Remote-Repositories.md
│ ├── 02-Pushing-to-remote-repositories.md
│ ├── 03-Practice-Test-Remote-Repositories.md
│ ├── 04-Cloning-Remote-Repositories.md
│ ├── 05-Practice-Test-Cloning-Remote-Repositories.md
│ ├── 06-Pull-Requests.md
│ ├── 07-Practice-Test-Pull-Requests.md
│ ├── 08-Fetching-and-Pulling.md
│ ├── 09-Practice-Test-Fetching-and-Pulling.md
│ ├── 10-Merge-Conflicts.md
│ ├── 11-Practice-Test-Merge-Conflicts.md
│ └── 12-Fork.md
├── 05-Git-Rebasing
│ ├── 01-Rebasing.md
│ ├── 02-Interactive-Rebasing.md
│ ├── 03-Practice-Test-Rebasing.md
│ ├── 04-Cherry-Picking.md
│ └── 05-Practice-Test-Cherry-Picking.md
└── 06-Resetting-and-Reverting
│ ├── 01-Resetting-and-Reverting.md
│ ├── 02-Practice-Test-Resetting-and-Reverting.md
│ ├── 03-Stashing.md
│ ├── 04-Practice-Test-Stashing.md
│ ├── 05-Reflog.md
│ ├── 06-Understanding-GIT.md
│ └── 07-Conclusion.md
└── images
├── README.md
├── ffb.PNG
├── frk.PNG
├── fth1.PNG
├── fth2.PNG
├── g1.PNG
├── g2.PNG
├── g3.PNG
├── g4.PNG
├── g5.PNG
├── g6.PNG
├── g7.PNG
├── git.PNG
├── gitlog.PNG
├── gitlog1.PNG
├── initgit.PNG
├── initgit1.PNG
├── initgit2.PNG
├── mc.PNG
├── mc1.PNG
├── mc2.PNG
├── mc3.PNG
├── nfb.PNG
├── pull1.PNG
├── pull2.PNG
├── pull3.PNG
├── r1.PNG
├── r2.PNG
├── r3.PNG
├── sshlink.PNG
├── sshlink1.PNG
├── sshlink2.PNG
├── sshlink3.PNG
├── t1.PNG
├── x1.PNG
├── x2.PNG
└── x3.PNG
/README.md:
--------------------------------------------------------------------------------
1 | # Git For Beginners
2 |
3 | These are notes from the [Git for Beginners Course](https://kodekloud.com/courses/git-for-beginners/) hosted on KodeKloud.
4 |
5 | # Sections
6 |
7 | - [01-Git-Course-Introduction](docs/01-Git-Course-Introduction)
8 | - [01-Git-Course-Introduction](docs/01-Git-Course-Introduction/01-Git-Course-Introduction.md)
9 |
10 | - [02-Git-Introduction](docs/02-Git-Introduction)
11 | - [01-Git-Introduction](docs/02-Git-Introduction/01-Git-Introduction.md)
12 | - [02-Local-and-Remote-Repositories](docs/02-Git-Introduction/02-Local-and-Remote-Repositories.md)
13 | - [03-Install-Git](docs/02-Git-Introduction/03-Install-Git.md)
14 | - [04-Lab-Introduction](docs/02-Git-Introduction/04-Lab-Introduction.md)
15 | - [05-Practice-Test-Install-Git](docs/02-Git-Introduction/05-Practice-Test-Install-Git.md)
16 | - [06-Initialize-a-Git-Repository](docs/02-Git-Introduction/06-Initialize-a-Git-Repository.md)
17 | - [07-Git-Log](docs/02-Git-Introduction/07-Git-Log.md)
18 | - [08-Practice-Test-Git-Log](docs/02-Git-Introduction/08-Practice-Test-Git-Log.md)
19 |
20 | - [03-Git-Branches](docs/03-Git-Branches)
21 | - [01-Git-Branches](docs/03-Git-Branches/01-Git-Branches.md)
22 | - [02-Practice-Test-Branches](docs/03-Git-Branches/02-Practice-Test-Branches.md)
23 | - [03-Git-Merging-Branches](docs/03-Git-Branches/03-Git-Merging-Branches.md)
24 | - [04-Practice-Test-Merging-Branches](docs/03-Git-Branches/04-Practice-Test-Merging-Branches.md)
25 |
26 | - [04-Initialize-Remote-Repositories](docs/04-Initialize-Remote-Repositories)
27 | - [01-Initialize-Remote-Repositories](docs/04-Initialize-Remote-Repositories/01-Initialize-Remote-Repositories.md)
28 | - [02-Pushing-to-remote-repositories](docs/04-Initialize-Remote-Repositories/02-Pushing-to-remote-repositories.md)
29 | - [03-Practice-Test-Remote-Repositories](docs/04-Initialize-Remote-Repositories/03-Practice-Test-Remote-Repositories.md)
30 | - [04-Cloning-Remote-Repositories](docs/04-Initialize-Remote-Repositories/04-Cloning-Remote-Repositories.md)
31 | - [05-Practice-Test-Cloning-Remote-Repositories](docs/04-Initialize-Remote-Repositories/05-Practice-Test-Cloning-Remote-Repositories.md)
32 | - [06-Pull-Requests](docs/04-Initialize-Remote-Repositories/06-Pull-Requests.md)
33 | - [07-Practice-Test-Pull-Requests](docs/04-Initialize-Remote-Repositories/07-Practice-Test-Pull-Requests.md)
34 | - [08-Fetching-and-Pulling](docs/04-Initialize-Remote-Repositories/08-Fetching-and-Pulling.md)
35 | - [09-Practice-Test-Fetching-and-Pulling](docs/04-Initialize-Remote-Repositories/09-Practice-Test-Fetching-and-Pulling.md)
36 | - [10-Merge-Conflicts](docs/04-Initialize-Remote-Repositories/10-Merge-Conflicts.md)
37 | - [11-Practice-Test-Merge-Conflicts](docs/04-Initialize-Remote-Repositories/11-Practice-Test-Merge-Conflicts.md)
38 | - [12-Fork](docs/04-Initialize-Remote-Repositories/12-Fork.md)
39 |
40 | - [05-Git-Rebasing](docs/05-Git-Rebasing)
41 | - [01-Rebasing](docs/05-Git-Rebasing/01-Rebasing.md)
42 | - [02-Interactive-Rebasing](docs/05-Git-Rebasing/02-Interactive-Rebasing.md)
43 | - [03-Practice-Test-Rebasing](docs/05-Git-Rebasing/03-Practice-Test-Rebasing.md)
44 | - [04-Cherry-Picking](docs/05-Git-Rebasing/04-Cherry-Picking.md)
45 | - [05-Practice-Test-Cherry-Picking](docs/05-Git-Rebasing/05-Practice-Test-Cherry-Picking.md)
46 |
47 | - [06-Resetting-and-Reverting](docs/06-Resetting-and-Reverting)
48 | - [01-Resetting-and-Reverting](docs/06-Resetting-and-Reverting/01-Resetting-and-Reverting.md)
49 | - [02-Practice-Test-Resetting-and-Reverting](docs/06-Resetting-and-Reverting/02-Practice-Test-Resetting-and-Reverting.md)
50 | - [03-Stashing](docs/06-Resetting-and-Reverting/03-Stashing.md)
51 | - [04-Practice-Test-Stashing](docs/06-Resetting-and-Reverting/04-Practice-Test-Stashing.md)
52 | - [05-Reflog](docs/06-Resetting-and-Reverting/05-Reflog.md)
53 | - [06-Understanding-GIT](docs/06-Resetting-and-Reverting/06-Understanding-GIT.md)
54 | - [07-Conclusion](docs/06-Resetting-and-Reverting/07-Conclusion.md)
55 |
--------------------------------------------------------------------------------
/docs/01-Git-Course-Introduction/01-Git-Course-Introduction.md:
--------------------------------------------------------------------------------
1 | # Git Course Introduction
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/git-course-introduction/)
3 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/01-Git-Introduction.md:
--------------------------------------------------------------------------------
1 | # Git Introduction
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/git-introduction/)
3 |
4 | In this section, we will take a look at Git Introduction
5 |
6 | ## Git
7 | - Git is a **`Distributed Version Control System`**
8 | - Git is a content tracker, it stores all our code changes.
9 |
10 | 
11 |
12 | - Distributed means it has a remote repository which is stored in a server and a local repository which is stored on the computer of every developer working on a project. Every developer has a full copy of the code base.
13 |
14 | 
15 |
16 | - We can go back in time, without loosing any new changes.
17 |
18 | 
19 |
20 | - You have access to entire project history
21 |
22 | 
23 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/02-Local-and-Remote-Repositories.md:
--------------------------------------------------------------------------------
1 | # Local and Remote Repositories
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/local-and-remote-repositories/)
3 |
4 | In this section, we will take a look at local and remote repositories
5 |
6 | ## Types of Repositories
7 | - Git has two repository types
8 | - Local Repository
9 | - Local Repository is on your own machine, so you have direct access to it.
10 | - Remote Repository
11 | - Remote Repository is usually a centralized server.
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/03-Install-Git.md:
--------------------------------------------------------------------------------
1 | # Install Git
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/install-git/)
3 |
4 | In this section, we will take a look at Installing Git
5 |
6 | - Download the Git binaries for your specific machine
7 | ```
8 | https://git-scm.com/downloads
9 | ```
10 | - Installing git for Linux
11 | ```
12 | https://git-scm.com/download/linux
13 | ```
14 | - Installing git for Mac
15 | ```
16 | https://git-scm.com/download/mac
17 | ```
18 | - Installing git for windows
19 | ```
20 | https://git-scm.com/download/win
21 | ```
22 | - Once, installed to check the version of the git run the below command
23 | ```
24 | $ git --version
25 | ```
26 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/04-Lab-Introduction.md:
--------------------------------------------------------------------------------
1 | # Lab - Introduction
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/lab-introduction/)
3 |
4 |
5 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/05-Practice-Test-Install-Git.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Install Git
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-install-git/)
3 |
4 | Solutions to practice test - Install git
5 |
6 | - Run the command cat /etc/*release* and identify the name
7 |
8 |
9 |
10 | ```
11 | $ cat /etc/*release*
12 | ```
13 |
14 |
15 |
16 | - Run sudo apt update and then sudo apt install git -y. Refer to the GIT installation documentation here: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
17 |
18 |
19 |
20 | ```
21 | $ sudo apt update
22 | $ sudo apt install git -y
23 | ```
24 |
25 |
26 |
27 | - Run git --version to check version
28 |
29 |
30 |
31 | ```
32 | $ git --version
33 | ```
34 |
35 |
36 |
37 | - Run git help command and look at the description of each command
38 |
39 |
40 |
41 | ```
42 | $ git help|more
43 | $ git show
44 | ```
45 |
46 |
47 |
48 | - Run git help command and look at the description of each command
49 |
50 |
51 |
52 | ```
53 | $ git help|more
54 | $ git branch
55 | ```
56 |
57 |
58 |
59 | - Run git help command and look at the description of each command
60 |
61 |
62 |
63 | ```
64 | $ git help|more
65 | $ git fetch
66 | ```
67 |
68 |
69 |
70 | - Run git help command and look at the description of each command
71 |
72 |
73 |
74 | ```
75 | $ git help|more
76 | $ git init
77 | ```
78 |
79 |
80 |
81 | - Run git help init command and identify the option used to create a bare repository
82 |
83 |
84 |
85 | ```
86 | $ apt-get install git-man
87 | $ git help init
88 | $ git init --bare
89 | ```
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/06-Initialize-a-Git-Repository.md:
--------------------------------------------------------------------------------
1 | # Initialize a Git Repository
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/intialize-a-git-repository/)
3 |
4 | In this section, we will take a look at initializing a git repository
5 |
6 | #### Let's initialize a local git repository
7 | - Go into a project folder and initialize git
8 | ```
9 | $ cd /Users/lydiahallie/Desktop/myproject
10 | $ git init
11 | ```
12 | - We have initizalized an empty git repository in a **`.git`** folder
13 |
14 | 
15 |
16 | - To list all the contents of the folder including the hidden folder such as .git folder
17 | ```
18 | $ ls -a
19 | ```
20 | #### Let's add a file to a project
21 | - Create a file with a basic sentence
22 | ```
23 | $ touch story1.txt
24 | $ echo "This is a beautiful story" >> story1.txt
25 | ```
26 | - To see the status of git
27 | ```
28 | $ git status
29 | ```
30 | ## git status
31 | - Default branch will be master branch
32 | - Untracked files are files that are not added to the git
33 |
34 | 
35 |
36 | ## git add
37 | - To add a file to the staging area
38 | ```
39 | $ git add story1.txt
40 | ```
41 |
42 | ## git commit
43 |
44 | - To commit the changes
45 | ```
46 | $ git commit -m "Added first story"
47 | ```
48 |
49 | 
50 |
51 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/07-Git-Log.md:
--------------------------------------------------------------------------------
1 | # Git Log
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/git-log/)
3 |
4 | To know about other commits information such as commit hash, the author name and the date
5 | ```
6 | $ git log
7 | ```
8 | 
9 |
10 | To easily show commit details as one line
11 | ```
12 | $ git log --oneline
13 | ```
14 |
15 | 
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/docs/02-Git-Introduction/08-Practice-Test-Git-Log.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Git Log
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-git-log/)
3 |
4 | Solutions to practice test - git log
5 |
6 | - We have initialised git repo in /home/sarah/story-blog. Check git log command output in that directory
7 |
8 |
9 |
10 | ```
11 | $ cd /home/sarah/story-blog
12 | $ git log
13 | ```
14 |
15 |
16 |
17 | - Run git add .;git commit -m "Added the lion and mouse story"
18 |
19 |
20 |
21 | ```
22 | $ git add .
23 | $ git commit -m "Added the lion and mouse story"
24 | ```
25 |
26 |
27 |
28 | - Check git log command output in that directory
29 |
30 |
31 |
32 | ```
33 | $ git log
34 | ```
35 |
36 |
37 |
38 | - Which info is not displayed in git log?
39 |
40 |
41 |
42 | ```
43 | List of changed files
44 | ```
45 |
46 | - You can list the changed files as well using the --name-only option with the git log command
47 |
48 |
49 |
50 | ```
51 | $ git log --name-only
52 | ```
53 |
54 |
55 |
56 | - Which branch has the changes been committed to?
57 |
58 |
59 |
60 | ```
61 | $ git log
62 | ```
63 |
64 |
65 |
66 | - Who is the Author of the commit in git repo?
67 |
68 |
69 |
70 | ```
71 | $ git log
72 | ```
73 |
74 |
75 |
76 | - Check git log where commit message is Added a new story
77 |
78 |
79 |
80 | ```
81 | $ git log --name-only
82 | ```
83 |
84 |
85 |
86 | - What is the option for git log command to display the logs in compact way (one log per line)?
87 |
88 |
89 |
90 | ```
91 | $ git log --oneline
92 | ```
93 |
94 |
95 |
96 | - Go to cd /home/sarah/learning-app-ecommerce and run git log
97 |
98 |
99 |
100 | ```
101 | $ cd /home/sarah/learning-app-ecommerce
102 | $ git status
103 | $ git log
104 | ```
105 |
106 |
107 |
108 | - You may list the last few commits alone using the --max-count option like this git log -n 3 or git log --max-count 3
109 |
110 |
111 |
112 | ```
113 | $ git log -n 3
114 | $ git log --max-count 3
115 | ```
116 |
117 |
118 |
119 | - Go to cd /home/sarah/learning-app-ecommerce and run git log -n 1
120 |
121 |
122 |
123 | ```
124 | $ git log -n 1
125 | $ git log --max-count 1
126 | ```
127 |
128 |
129 |
130 |
131 | - Go to cd /home/sarah/learning-app-ecommerce and run git log --name-only and look for the commit that changed the file js/theme.js
132 |
133 |
134 |
135 | ```
136 | $ cd /home/sarah/learning-app-ecommerce
137 | $ git log --name-only
138 | ```
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/docs/03-Git-Branches/01-Git-Branches.md:
--------------------------------------------------------------------------------
1 | # Git Branches
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/git-branches/)
3 |
4 | In this section, we will take a look at git branches
5 |
6 | ## Branches
7 | - Keep project versioned using branch
8 | - A branch is basically a pointer to the last commit
9 |
10 | 
11 |
12 | - If you are working on a feature, you might work on a feature branch (eg. feature/signup), once the features are tested, you can merge to master branch
13 |
14 | 
15 |
16 | - To create a new branch
17 | ```
18 | $ git branch sarah
19 | ```
20 |
21 | - To create a new branch and switch to it
22 | ```
23 | $ git checkout -b sarah
24 | ```
25 |
26 | - To list of all of our branches
27 | ```
28 | $ git branch
29 | ```
30 |
31 | 
32 |
33 | - Switch to exisiting branch
34 | ```
35 | $ git checkout sarah
36 | ```
37 |
38 | - Delete a branch
39 | ```
40 | $ git branch -d max
41 | ```
42 |
43 |
44 |
--------------------------------------------------------------------------------
/docs/03-Git-Branches/02-Practice-Test-Branches.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Branches
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-branches-checkout-push-branch/)
3 |
4 | Solutions to practice test - Branches
5 | - Refer the previous lecture, Branch is nothing but a pointer to a specific commit in GIT
6 |
7 |
8 |
9 | ```
10 | Pointer to a specific commit in git
11 | ```
12 |
13 |
14 |
15 | - By default the branch used is master
16 |
17 | - Simply run cd /home/sarah/story-blog; git log --name-only
18 |
19 |
20 |
21 | ```
22 | $ cd /home/sarah/story-blog
23 | $ git log --name-only
24 | ```
25 |
26 |
27 |
28 | - Check branch in the git log --decorate output
29 |
30 |
31 |
32 | ```
33 | $ git log --decorate
34 | ```
35 |
36 |
37 |
38 | - Run git checkout -b story/frogs-and-ox
39 |
40 |
41 |
42 | ```
43 | $ git checkout -b story/frogs-and-ox
44 | ```
45 |
46 |
47 |
48 | - Check branch HEAD pointer in git log output
49 |
50 |
51 |
52 | ```
53 | $ git log
54 | ```
55 |
56 |
57 |
58 | - Run git add frogs-and-ox.txt; git commit -am 'Add incomplete frogs-and-ox story'
59 |
60 |
61 |
62 | ```
63 | $ git add frogs-and-ox.txt
64 | $ git commit -am 'Add incomplete frogs-and-ox story'
65 | ```
66 |
67 |
68 |
69 | - Run git checkout master
70 |
71 |
72 |
73 | ```
74 | $ git checkout master
75 | ```
76 |
77 |
78 |
79 | - Use vi editor to edit the file and fix the typo. Then run the command git commit -am 'Fix typo in story title'
80 |
81 |
82 |
83 | ```
84 | $ git commit -am 'Fix typo in story title'
85 | ```
86 |
87 |
88 |
89 | - Run the command git checkout story/frogs-and-ox
90 |
91 |
92 |
93 | ```
94 | $ git checkout story/frogs-and-ox
95 | ```
96 |
97 |
98 |
99 | - Run the command git commit -am 'Completed frogs-and-ox story'
100 |
101 |
102 |
103 | ```
104 | $ git commit -am 'Completed frogs-and-ox story'
105 | ```
106 |
107 |
108 |
109 | - Change to directory cd /home/sarah/website and run git branch command
110 |
111 |
112 |
113 | ```
114 | $ cd /home/sarah/website
115 | $ git branch
116 | ```
117 |
118 |
119 |
120 | - Checkout to directory git checkout feature/signout; git log --graph --decorate
121 |
122 |
123 |
124 | ```
125 | $ git checkout feature/signout
126 | $ git log --graph --decorate
127 | ```
128 |
129 |
130 |
131 | - Checkout to directory git checkout feature/signout; git log --graph --decorate
132 |
133 |
134 |
135 | ```
136 | $ git checkout feature/signout
137 | $ git log --graph --decorate
138 | ```
139 |
140 |
141 |
--------------------------------------------------------------------------------
/docs/03-Git-Branches/03-Git-Merging-Branches.md:
--------------------------------------------------------------------------------
1 | # Git Merging Branches
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/git-merging-branches/)
3 |
4 | In this section, we will take a look at git merging braches
5 |
6 | #### We can merge a branch with 'git merge' command
7 | ```
8 | $ git checkout master
9 | $ git merge feature/signup
10 | ```
11 |
12 | #### Two types of merge that git can perform
13 | 1. Fast forward merge
14 |
15 | 
16 |
17 | 2. No-Fast Forward merge
18 |
19 | 
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/docs/03-Git-Branches/04-Practice-Test-Merging-Branches.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Merging Branches
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-merging-branches/)
3 |
4 | Solutions to practice test - merging branches
5 | - Run cd /home/sarah/story-blog; git checkout master and then list the files ls
6 |
7 |
8 |
9 | ```
10 | $ cd /home/sarah/story-blog
11 | $ git checkout master
12 | $ ls
13 | ```
14 |
15 |
16 |
17 | - Run cd /home/sarah/story-blog and then list the files ls
18 |
19 |
20 |
21 | ```
22 | $ cd /home/sarah/story-blog
23 | $ ls
24 | ```
25 |
26 |
27 | - Run git branch
28 |
29 |
30 |
31 | ```
32 | $ git branch
33 | ```
34 |
35 |
36 |
37 | - Run git log
38 |
39 |
40 |
41 | ```
42 | $ git checkout master
43 | $ git log
44 | $ git checkout story/frogs-and-on
45 | $ git log
46 | ```
47 |
48 |
49 |
50 | - Run git merge story/frogs-and-ox. Check git log now and it should show commit message as Merge branch 'story/frogs-and-ox' into master
51 |
52 |
53 |
54 | ```
55 | $ git checkout master
56 | $ git merge story/frogs-and-ox
57 | $ git log
58 | ```
59 |
60 |
61 |
62 | - List the files in the master branch and make sure both the stories are visible.
63 |
64 |
65 |
66 | ```
67 | $ ls
68 | ```
69 |
70 |
71 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/01-Initialize-Remote-Repositories.md:
--------------------------------------------------------------------------------
1 | # Initialize Remote Repositories
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/initialize-remote-repositories/)
3 |
4 | In this section, we will take a look at initializing remote repositories
5 |
6 | #### We can push code to the remote repositories that is hosted at somewhere else and get this code on our local machines by pulling this information.
7 | - There are several platforms where we can host our remote repositories. Most commonly used one are the below
8 | 1. Github
9 | 1. Gitlab
10 | 1. Bitbucket
11 |
12 | - Once we initialize a repository on those platform, we will get access to something called **`connection string`**.
13 |
14 | - A connection string is the URL that we can use in order to let git know where the remote repository is located.
15 |
16 | 
17 |
18 | - To add a remote repository to a local project
19 | ```
20 | $ git add remote origin
21 | ```
22 |
23 | 
24 |
25 | - To list all remote repositories
26 | ```
27 | $ git remote -v
28 | ```
29 |
30 | 
31 |
32 |
33 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/02-Pushing-to-remote-repositories.md:
--------------------------------------------------------------------------------
1 | # Pushing to remote repositories
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/pushing-to-remote-repositories/)
3 |
4 | In this section, we will take a look at pushing to remote repositories
5 |
6 | #### In order to keep our local and remote repo in sync, we have to push the data from local repo to remote repo
7 | - To push data from local to remote repo
8 | ```
9 | $ git push origin master
10 | ```
11 |
12 | 
13 |
14 |
15 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/03-Practice-Test-Remote-Repositories.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Remote Repositories
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-remote-repositories/)
3 |
4 | Solutions to practice test - Remote Repositories
5 | - Run cd /home/sarah/story-blog; git log
6 |
7 |
8 |
9 | ```
10 | $ cd /home/sarah/story-blog
11 | $ git log --oneline
12 | ```
13 |
14 |
15 |
16 | - Count the number of stories in the master branch
17 |
18 |
19 |
20 | ```
21 | $ ls
22 | ```
23 |
24 |
25 |
26 | - Login to UI with given credentials. Click on + sign to create new repository. Add Repository Name:story-blog and keep other options default. Then click on Create repository
27 |
28 | - Run cd /home/sarah/story-blog; git remote add origin http://git.example.com/sarah/story-blog.git
29 |
30 |
31 |
32 | ```
33 | $ cd /home/sarah/story-blog
34 | $ git remote add origin http://git.example.com/sarah/story-blog.git
35 | $ git remote -v
36 | ```
37 |
38 |
39 |
40 | - Syntax: git push
41 |
42 |
43 |
44 | ```
45 | $ git push origin master
46 | ```
47 |
48 |
49 |
50 | - Simply run git push origin master to push and input login credentials
51 |
52 |
53 |
54 | ```
55 | $ git push origin master
56 | ```
57 |
58 |
59 |
60 | - Looking at the remote repository on Gitea can you identify the total disk space consumed by this repository?
61 |
62 |
63 |
64 | ```
65 | 20KiB
66 | ```
67 |
68 |
69 |
70 | - In the top menu bar select Explore -> Users
71 |
72 |
73 |
74 | ```
75 | From GUI --> Explore --> Users ( Count the users)
76 | ```
77 |
78 |
79 |
80 | - In the top menu bar select Explore -> Repositories and count the number of repositories for each user.
81 |
82 |
83 |
84 | ```
85 | From GUI --> Explore --> Repositories
86 | ```
87 |
88 |
89 |
90 | - In the top menu bar select Explore -> Repositories -> tej/ecommerce and look at the number of commits.
91 |
92 |
93 |
94 | ```
95 | From GUI --> Explore --> Repositories --> tej/ecommerce
96 | ```
97 |
98 |
99 |
100 | - Go to story-bloggg repository in GUI and click on settings. Scroll all the way down and click on Delete This Repository option. Then follow the instructions.
101 |
102 |
103 |
104 | ```
105 | From GUI --> Repositories --> sarah/story-bloggg --> "Delete this repository"
106 | ```
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/04-Cloning-Remote-Repositories.md:
--------------------------------------------------------------------------------
1 | # Cloning Remote Repositories
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/cloning-remote-repositories/)
3 |
4 | In this section, we will take a look at cloning remote repositories
5 |
6 | #### We can clone the remote repository on our local machines
7 | - To clone remote repo with ssh link
8 | ```
9 | $ git clone
10 | ```
11 |
12 | 
13 |
14 | 
15 |
16 | ```
17 | $ git clone git@github.com:account/remote-repo.git
18 | ```
19 |
20 | 
21 |
22 | - To check the history of the project
23 | ```
24 | $ cd remote-repo
25 | $ git log
26 | ```
27 |
28 | 
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/05-Practice-Test-Cloning-Remote-Repositories.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Cloning Remote Repositories
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/lab-cloning-remote-repositories/)
3 |
4 | Solutions to practice test - cloning remote repositories
5 | - Run cd /home/max; git clone http://git.example.com/sarah/story-blog.git
6 |
7 |
8 |
9 | ```
10 | $ cd /home/max
11 | $ git clone http://git.example.com/sarah/story-blog.git
12 | ```
13 |
14 |
15 |
16 | - Check the contents of the cloned repository. Confirm that you can see Sarah's story and history of commit by running git log and validate author info, commit message etc.
17 |
18 |
19 |
20 | ```
21 | $ cd /home/max
22 | $ git log
23 | ```
24 |
25 |
26 |
27 | - Max has written his story about The 🦊 Fox and Grapes 🍇 View the file he created and its contents. You may read the story if you wish to. But don't spend all day 😝
28 |
29 |
30 |
31 | ```
32 | $ cd /home/max
33 | $ cat fox-and-grapes.txt
34 | ```
35 |
36 |
37 |
38 | - Run git add fox-and-grapes.txt and then git commit -m 'Added fox-and-grapes story'
39 |
40 |
41 |
42 | ```
43 | $ cd /home/max
44 | $ git add fox-and-grapes
45 | $ git config user.email "max@example.com"
46 | $ git config user.name "max"
47 | ```
48 |
49 |
50 |
51 | - Run the git remote -v command to check the remote repository
52 |
53 |
54 |
55 | ```
56 | $ git remote -v
57 | ```
58 |
59 |
60 |
61 | - Run git push origin master
62 |
63 |
64 |
65 | ```
66 | $ cd /home/max
67 | $ git push origin master
68 | ```
69 |
70 |
71 |
72 | - The account owner - Sarah needs to add you as a collaborator. While logged in to the Gitea UI as user sarah go to Settings -> Collaborators of the project and add max as collaborate with Write permissions.
73 |
74 |
75 |
76 | ```
77 | From GUI --> Repositories --> sarah/story-blog --> settings --> collaborators
78 | ```
79 |
80 |
81 |
82 |
83 | - Simply run git push origin master to push and input login credentials
84 |
85 |
86 |
87 | ```
88 | $ cd /home/max
89 | $ git push origin master
90 | ```
91 |
92 |
93 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/06-Pull-Requests.md:
--------------------------------------------------------------------------------
1 | # Pull Requests
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/pull-requests/)
3 |
4 | In this section, we will take a look at Pull requests
5 |
6 |
7 | To push the latest changes to github sarah branch
8 | ```
9 | $ git push origin sarah
10 | ```
11 |
12 | To push changes from sarah to master we have to open something called **`Pull Request`**
13 |
14 | 
15 |
16 | 
17 |
18 | 
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/07-Practice-Test-Pull-Requests.md:
--------------------------------------------------------------------------------
1 | # Pull requests
2 | - Take me to [Practice Test](https://kodekloud.com/topic/labs-pull-requests/)
3 |
4 | Solutions to practice test - pull requests
5 |
6 | - Run cd /home/max; git clone http://git.example.com/sarah/story-blog.git
7 |
8 |
9 |
10 | ```
11 | $ cd /home/max
12 | $ git clone http://git.example.com/sarah/story-blog.git
13 | ```
14 |
15 |
16 |
17 | - View the file he created and its contents. You may read the story if you wish to. What's the status of the file in the git repo?
18 |
19 |
20 |
21 | ```
22 | $ cd /home/max/story-blog
23 | $ git status
24 | ```
25 |
26 |
27 |
28 | - Run git checkout -b story/fox-and-grapes; git add .; git commit -m 'Added fox-and-grapes story'
29 |
30 |
31 |
32 | ```
33 | $ cd /home/max/story-blog
34 | $ git checkout -b story/fox-and-grapes
35 | $ git add .
36 | $ git commit -m 'Added fox-and-grapes story'
37 | ```
38 |
39 |
40 |
41 | - Run the command git push origin story/fox-and-grapes to push and input login credentials
42 |
43 |
44 |
45 | ```
46 | $ cd /home/max/story-blog
47 | $ git push origin story/fox-and-grapes
48 | ```
49 |
50 |
51 |
52 | - Follow below steps to create PR
53 |
54 |
55 |
56 | - Login to Git Portal UI with max user
57 |
58 | - Go to the story-blog repository
59 |
60 | - Click on Pull requests
61 |
62 | - Click on New Pull request
63 |
64 | - Put PR pull from branch: story/fox-and-grapes
65 |
66 | - Put PR merge into branch: master
67 |
68 | - Click on New Pull Request
69 |
70 | - Add PR title as Added fox-and-grapes story
71 |
72 | - Click on Create Pull request
73 |
74 |
75 |
76 | - Go to the newly created PR
77 |
78 |
79 |
80 | - Click on Reviewers on the right
81 |
82 | - Add tom as a reviewer to the PR
83 |
84 |
85 |
86 | - Sign out of Git Portal UI as max user
87 |
88 |
89 |
90 | - Login as tom user
91 |
92 | - Go to story-blog repo and click on Pull Requests
93 |
94 | - Click on the PR - Added fox-and-grapes story
95 |
96 | - Click on Files changed tab and then the green drop down button Review. Add any approval message and click on the Approve button to approve the PR. You may need to scroll down to see the Approve button.
97 |
98 |
99 |
100 | - Logout of tom user
101 |
102 |
103 |
104 | - login with the user sarah
105 |
106 | - Select the PR
107 |
108 | - Click on the green button Merge Pull Request and then confirm again by clicking on the green button Merge Pull Request to merge the PR
109 |
110 | - PR status should be shown as Merged
111 |
112 |
113 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/08-Fetching-and-Pulling.md:
--------------------------------------------------------------------------------
1 | # Fetching and Pulling
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/fetching-and-pulling/)
3 |
4 | In this section, we will take a look at fetching and pulling
5 |
6 | To update remote repository in our local repo
7 | ```
8 | $ git fetch origin master
9 | ```
10 |
11 | 
12 |
13 | To update local master branch to point to the latest changes made on remote branch(origin/master). To merge origin/master into local master branch
14 | ```
15 | $ git merge origin/master
16 | ```
17 |
18 | To pull the remote branch
19 | ```
20 | $ git pull origin/master
21 | ```
22 |
23 | 
24 |
25 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/09-Practice-Test-Fetching-and-Pulling.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Fetching and Pulling
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-fetching-and-pulling/)
3 |
4 | Solutions to practice test - fetching and pulling
5 |
6 | - Run git checkout master; git fetch origin master to fetch remote changes
7 |
8 |
9 |
10 | ```
11 | $ git checkout master
12 | $ git fetch origin master
13 | ```
14 |
15 |
16 |
17 | - To view all the branches- both local and remote - run the git branch -a command.
18 |
19 |
20 |
21 | ```
22 | $ git branch -a
23 | ```
24 |
25 |
26 |
27 | - Run git merge origin/master
28 |
29 |
30 |
31 | ```
32 | $ git merge origin/master
33 | ```
34 |
35 |
36 |
37 | - Run git pull origin master
38 |
39 |
40 |
41 | ```
42 | $ git pull origin master
43 | ```
44 |
45 |
46 |
47 | - Run the ls command while in the master branch
48 |
49 |
50 |
51 | ```
52 | $ ls
53 | ```
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/10-Merge-Conflicts.md:
--------------------------------------------------------------------------------
1 | # Merge Conflicts
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/git-merge-conflicts/)
3 |
4 | In this section, we will take a look at merge conflicts
5 |
6 | 
7 |
8 | #### Remove the lines that we don't wanna keep to resolve the conficts and save the file.
9 |
10 | 
11 |
12 | 
13 |
14 | ` Add the changes to git again
15 | ```
16 | $ git add fourth_story.txt
17 | ```
18 |
19 | 
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/11-Practice-Test-Merge-Conflicts.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Merge Conflicts
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-merge-conflicts/)
3 |
4 | Solutions to practice test - merge conflicts
5 |
6 | - Run git add story-index.txt; git commit -am 'Add index of stories'
7 |
8 |
9 |
10 | ```
11 | $ git add story-index.txt
12 | $ git commit -am 'Add index of stories'
13 | ```
14 |
15 |
16 |
17 | - Run the command git push origin master. It should fail with the rejected message
18 |
19 |
20 |
21 | ```
22 | $ git push origin master
23 | ```
24 |
25 |
26 |
27 | - Read the error message and identify the cause of the failure.
28 |
29 |
30 |
31 | ```
32 | The remote contains the work you do not have locally
33 | ```
34 |
35 |
36 |
37 | - Run git pull origin master
38 |
39 |
40 |
41 | ```
42 | $ git pull origin master
43 | ```
44 |
45 |
46 |
47 | - What was the result of the Pull operation?
48 |
49 |
50 |
51 | ```
52 | Merge Conflict
53 | ```
54 |
55 |
56 |
57 | - Run git log origin/master
58 |
59 |
60 |
61 | ```
62 | $ git log origin/master
63 | ```
64 |
65 |
66 |
67 | - Inspect the file (use vi editor or just cat story-index.txt) and select the most appropriate statement below. The first section shows Max's data and the second section shows Sarah's data.
68 |
69 |
70 |
71 | ```
72 | sarah missed the Donkey and Dog story, Max mis-spelt the lion and mouse story
73 | ```
74 |
75 |
76 |
77 | - Update the contents of the file (use vi editor) to keep the correct version of the Lion and Mouse story and keep the Donkey and Dog story as well. Remove all the extra lines added by GIT
78 |
79 |
80 |
81 | ```
82 | $ cat story-index.txt
83 | 1. The Lion and the Mouse
84 | 2. The Frogs and the Ox
85 | 3. The Fox and the Grapes
86 | 4. The Donkey and the Dog
87 | ```
88 |
89 | - Run the command git commit -am 'Resolved merge conflicts and merged story index'
90 |
91 |
92 |
93 | ```
94 | $ git commit -am 'Resolved merge conflicts and merged story index'
95 | ```
96 |
97 |
98 |
99 | - Run the command git push origin master. It should now go through without an issue.
100 |
101 |
102 |
103 | ```
104 | $ git push origin master
105 | ```
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/docs/04-Initialize-Remote-Repositories/12-Fork.md:
--------------------------------------------------------------------------------
1 | # Fork
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/fork/)
3 |
4 | #### How do you create a pull request if you are not part of a git project?
5 | - One way to contribute such projects is to **`fork`** the main project.
6 | - After forking the project you can add your changes to a branch on the fork copy and send a pull request to the original project to merge your changes
7 |
8 | 
9 |
10 |
--------------------------------------------------------------------------------
/docs/05-Git-Rebasing/01-Rebasing.md:
--------------------------------------------------------------------------------
1 | # Git Rebasing
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/rebasing/)
3 |
4 | 
5 |
6 | - In this section, we will take a look at git rebasing.
7 |
8 | ### Git merge
9 | - We can merge the master branch into our own branch by `git merge` command.
10 | - This creates a new merge commit, to merge these changes into the our own branch. Another way to achieving this, by rebasing branches.
11 | ```
12 | $ git merge master
13 | ```
14 |
15 | ### Git rebase
16 | - Basically in the rebasing, we are putting branch into top of the another branch one.
17 | - After performing this, current branch is containing all the changes that were made in the master branch.
18 |
19 | ```
20 | $ git rebase master
21 | ```
22 | - In the GIT, each commit has the unique identifier. This unique identifier is a hash that contains the information about the commit.
23 | - When its merge, this unique identifer won't be modified. In the other words, we are not modifying the history of the GIT commits. When we are merging.
24 | - When we are rebasing, actually we are copying commits from one branch to the another branch. Each time a hash value will update.
--------------------------------------------------------------------------------
/docs/05-Git-Rebasing/02-Interactive-Rebasing.md:
--------------------------------------------------------------------------------
1 | # Git Interactive Rebasing
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/interactive-rebasing/)
3 |
4 | 
5 |
6 |
7 | - In this section, we will take a look at git interactive-rebasing.
8 | - When all commits are looking same and should be added into the single commit.
9 | - We can change the history of the git branch within the interactive rebase. To access this we use `-i` flag with `git rebase` command.
10 | - We have to specify which commits we want to update.
11 | - Suppose we wants to modify first four commits. We are telling to git to rebase last 4 commits.
12 |
13 | ```
14 | $ git rebase -i HEAD~4
15 |
16 | ```
17 | 
18 |
19 |
20 | - It will open the file into the editor, we need to change "pick" to "squash" command. After changing the commands save the file and exit.
21 |
22 | 
23 |
24 | - After this, it will combined the commits. There are so many other options when you are interactively rebasing. It's very powerful tool to changes to your branch and commits.
25 |
--------------------------------------------------------------------------------
/docs/05-Git-Rebasing/03-Practice-Test-Rebasing.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Rebasing
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-rebasing/)
3 |
4 | Solutions to practice test - Git Rebasing
5 | - Click on the **Gitea Portal UI** button and enter the credentials given in the screen. Open the **sarah** story-blog repository. Click on the **Commits**.
6 |
7 | Solution
8 |
9 | ```
10 | $ Last commit has done by tom
11 | ```
12 |
13 |
14 | - Run the command to pull all the changes from remote to our local master branch.
15 |
16 | Solution
17 |
18 | ```
19 | $ cd /home/sarah/story-blog
20 | $ git checkout master
21 | $ git pull origin master
22 | ```
23 |
24 |
25 | - Run the following command to check the availability of the story-index.txt file in the current working directory.
26 |
27 | Solution
28 |
29 | ```
30 | $ ls
31 | ```
32 |
33 |
34 | - Run the following command to checkout the story/hare-and-tortoise branch and count the total of commits.
35 |
36 | Solution
37 |
38 | ```
39 | $ git checkout story/hare-and-tortoise
40 | $ git log --oneline
41 | ```
42 |
43 |
44 | - Run the following command to checkout the story/hare-and-tortoise branch and then rebase master branch.
45 |
46 | Solution
47 |
48 | ```
49 | $ git checkout story/hare-and-tortoise
50 | $ git rebase master
51 | ```
52 |
53 |
54 | - Run the following command to check the current status of commit.
55 |
56 | Solution
57 |
58 | ```
59 | $ git log
60 | ```
61 |
62 |
63 | - Run the following command to squash all the commits into a single commit. It opens the editor. Leave the first line and change the second and third lines to use `squash` instead of `pick` then save the file and exit with `:wq`. It will open again a file in the editor. Add the commit message "Add hare-and-tortoise story" with press `i` then save the file and exit with `:wq`.
64 |
65 | Solution
66 |
67 | ```
68 | $ git rebase -i HEAD~3
69 | ```
70 |
71 |
--------------------------------------------------------------------------------
/docs/05-Git-Rebasing/04-Cherry-Picking.md:
--------------------------------------------------------------------------------
1 | # Git Cherry Picking
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/cherry-picking/)
3 |
4 | 
5 |
6 | - In this section, we will take a look at `git cherry-pick` command.
7 | - One branch has certain changes and you would like to apply into the other branch. But you don't want to all the changes that you made in that branch. In the certain things, we use `cherry-pick` command to copy of that commits onto own branch.
8 | - We use hash of the commit, that we want to use for a cherry-pick. After running this command, it will create a copy of the commit into the specified branch.
9 |
10 | ```
11 | $ git cherry-pick aaba5
12 | ```
13 |
--------------------------------------------------------------------------------
/docs/05-Git-Rebasing/05-Practice-Test-Cherry-Picking.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Cherry Picking
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-cherry-picking/)
3 |
4 | Solutions to practice test - Cherry Picking
5 | - Move into the directory with `cd` command and check the content of the given file name with `cat` command.
6 |
7 | Solution
8 |
9 | ```
10 | $ cd story-blog
11 | $ cat story-index.txt
12 | ```
13 |
14 |
15 | - Run the following command to check the hash value of the commit that contains commit message "Updated the story index file" in the master branch.
16 |
17 | Solution
18 |
19 | ```
20 | $ git log master --oneline
21 |
22 | ```
23 |
24 |
25 | - Run the following command to switch into the given branch and perform cherry-pick command.
26 |
27 | Solution
28 |
29 | ```
30 | $ git checkout story/hare-and-tortoise
31 | $ git cherry-pick < write commit hash value identified in the previous step >
32 | ```
33 |
--------------------------------------------------------------------------------
/docs/06-Resetting-and-Reverting/01-Resetting-and-Reverting.md:
--------------------------------------------------------------------------------
1 | # Git Resetting and Reverting
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/resetting-and-reverting/)
3 |
4 | 
5 |
6 |
7 | - In this section, we will take a took at `git reset` and `git revert` command.
8 | - Everyone makes a mistake, in some situation we don't want to commit certain things but do. So there is a several options to undo that commit.
9 | - One of the option is `git revert` command. Second one is `git reset` command.
10 |
11 | ### Git revert
12 | - `git revert` command creates a new commit, which literally reverse the only changes that we made on the commit that we specified. A `git revert` command is useful if you want to undo the changes and keep those changes in your GIT history.
13 |
14 | ```
15 | $ git revert
16 | ```
17 |
18 | ### Git reset
19 | - In the `git reset` command, there is two ways to reset the commit. Either with the `--soft` flag which we wants to keep the changes that we made or over the `--hard` flag in order to loose all the changes that we made on that commit.
20 |
21 | ```
22 | # soft reset
23 | $ git reset --soft HEAD~1
24 |
25 | # hard reset
26 | $ git reset --hard HEAD~1
27 | ```
28 |
29 | - When we reset the commit with `--soft` flag, we still have the access to changes that we made by that commit. We can see that status by `git status` command. We can easily create an another commit this way.
30 |
31 | ```
32 | $ git reset --soft HEAD~1
33 | $ git status
34 | On branch sarah
35 | Changes to be committed:
36 | added: third_story.txt # file shown with git status command
37 | ```
38 |
39 | - In the `--hard` flag, it will reset the commit without saving all those changes.
40 |
41 | ```
42 | $ git reset --hard HEAD~1
43 | $ git status
44 | On branch sarah
45 | Nothing to commit
46 | ```
47 |
--------------------------------------------------------------------------------
/docs/06-Resetting-and-Reverting/02-Practice-Test-Resetting-and-Reverting.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Resetting and Reverting
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-resetting-and-reverting/)
3 |
4 | Solutions to practice test - Resetting and Reverting
5 | - Run the `cd` command to move into the story-blog directory.
6 |
7 | Solution
8 |
9 | ```
10 | $ cd story-blog
11 | ```
12 |
13 |
14 | - Run the `git log` command with it's appropriate option to check the history of commits with changed files lists.
15 |
16 | Solution
17 |
18 | ```
19 | $ git log --name-only
20 | # count the number of files changed in the last commit.
21 | ```
22 |
23 |
24 | - Run the `git revert` command to undo all the changes made in the previous commit. It will open the file in the editor, we don't need to change anything. Save the file with default commit message.
25 |
26 | Solution
27 |
28 | ```
29 | $ git log
30 | $ git revert
31 | ```
32 |
33 |
34 | - Run the `git reset` command with it's appropriate option which can be used to retain changes that were made on target commit after the reset operation.
35 |
36 | Solution
37 |
38 | ```
39 | $ git help reset
40 | $ git reset --soft
41 | ```
42 |
43 |
44 | - Run the `git reset` command with it's appropriate option which can be used to drop changes that were made on target commit after the reset operation.
45 |
46 | Solution
47 |
48 | ```
49 | $ git help reset
50 | $ git reset --hard
51 | ```
52 |
53 |
54 | - Run the `git reset` command to revert the last commit but retain the unfinished changes. The last commit must not be part of the GIT history.
55 |
56 | Solution
57 |
58 | ```
59 | $ git help reset
60 | $ git reset --soft HEAD~1
61 | ```
62 |
63 |
64 | - Run the `git commit` command to commit the latest changes done in the file.
65 |
66 | Solution
67 |
68 | ```
69 | $ git commit -am 'Finish hair-and-tortoise story'
70 | ```
71 |
72 |
73 | - Run the `git log` command to check the logs and count the number of commits made since she previously finished her story.
74 |
75 | Solution
76 |
77 | ```
78 | $ git log
79 | $ git log --name-only # With file name
80 | ```
81 |
82 |
83 | - Run the `git reset` command with it's appropriate option to remove all commits and changes she made since the commit "Finish hair-and-tortoise story".
84 |
85 | Solution
86 |
87 | ```
88 | $ git log
89 | $ git reset --hard HEAD~3
90 | ```
91 |
--------------------------------------------------------------------------------
/docs/06-Resetting-and-Reverting/03-Stashing.md:
--------------------------------------------------------------------------------
1 | # Git Stashing
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/stashing/)
3 |
4 | In this section, we will take a took at `git stash` command.
5 |
6 | ### git stash
7 |
8 | - If we don't want to commit now, we can stash all changes in the working area with `git stash` command. Modification in the working area, all get added to the stash.
9 |
10 | ```
11 | $ git stash
12 | ```
13 | - With `git stash pop` command, to get back changes in our working area.
14 |
15 | ```
16 | $ git stash pop
17 | ```
18 |
19 | - To see the list of stash files, we can run the following command:
20 |
21 | ```
22 | $ git stash list
23 | ```
24 |
25 | - To see the content of the specific stash file, we can run the following command:
26 |
27 | ```
28 | $ git stash show stash@{1}
29 | ```
30 |
31 | - To pop the specific stash, we can run the following command:
32 |
33 | ```
34 | $ git stash pop stash@{2}
35 |
36 | ```
37 |
--------------------------------------------------------------------------------
/docs/06-Resetting-and-Reverting/04-Practice-Test-Stashing.md:
--------------------------------------------------------------------------------
1 | # Practice Test - Stashing
2 | - Take me to [Practice Test](https://kodekloud.com/topic/lab-stashing/)
3 |
4 | Solutions to practice test - Stashing
5 | - Run the `cd` command to move into the **story-blog** directory and their check the content of the lion-and-mouse.txt file. Something is wrong written in the file.
6 |
7 | Solution
8 |
9 | ```
10 | $ cd story-blog
11 | $ cat lion-and-mouse.txt
12 | ```
13 |
14 |
15 | - Run the `git stash` command to stash the current changes before heading over to the master branch.
16 |
17 | Solution
18 |
19 | ```
20 | $ git stash
21 | ```
22 |
23 |
24 | - Run the `git checkout` command to switch into the **master** branch. To fix the error and commit the changes.
25 |
26 | Solution
27 |
28 | ```
29 | $ git checkout master
30 | # Edit the file lion-and-mouse.txt and fix the typo
31 | $ git commit -am 'Fixed title error'
32 | ```
33 |
34 |
35 | - Run the `git checkout` command to switch into the **story/frogs-and-ox** branch and pop the stash to retrieve the stashed changes.
36 |
37 | Solution
38 |
39 | ```
40 | $ git checkout story/frogs-and-ox
41 | $ git stash pop
42 | # To retrieve frogs-and-ox.txt file
43 | ```
44 |
45 |
46 | - Run the `git checkout` command to switch into the **story/multi-part-story** branch and find the list of stories that were stashed.
47 |
48 | Solution
49 |
50 | ```
51 | $ git checkout story/multi-part-story
52 | $ git stash list
53 | ```
54 |
55 |
56 | - To figure out what files are stashed in which of these stashes. Run the `git stash` command with it's appropriate option.
57 |
58 | Solution
59 |
60 | ```
61 | $ git stash list
62 | $ git stash show stash@{0}
63 | $ git stash show stash@{1}
64 | $ git stash show stash@{2}
65 | ```
66 |
67 |
68 | - Run the `git stash` command to figure out what order were the files pushed to the stash. Order should be earliest to latest.
69 |
70 | Solution
71 |
72 | ```
73 | # stash@{0} is the last(latest), stash@{2} is the first(earliest)
74 | $ git stash show stash@{0}
75 | $ git stash show stash@{1}
76 | $ git stash show stash@{2}
77 | ```
78 |
79 |
80 | - To figure out, if we do pop the stash now, which file would be retrieved? Run the `git stash` command and it's approriate option to check the list of stashes.
81 |
82 | Solution
83 |
84 | ```
85 | $ git stash list
86 | $ git stash pop
87 | # The last stashed commits are popped first.
88 | ```
89 |
90 |
--------------------------------------------------------------------------------
/docs/06-Resetting-and-Reverting/05-Reflog.md:
--------------------------------------------------------------------------------
1 | # Git Reflog
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/reflog/)
3 |
4 | In this section, we will take a took at `git reflog` command.
5 |
6 | - If commit is not neccessary at all and wants to remove then we can run the `git reset --hard` command: -
7 |
8 | ```
9 | $ git reset --hard HEAD~1
10 | ```
11 |
12 | - After running this command, that data will be gone forever. But we don't need to be panic at all, `git reflog` command shows the all actions that have been taken to the repository. This includes resets, reverts and merges.
13 |
14 | ```
15 | $ git reflog
16 | ```
17 |
18 | - You can easily undo the mistakes you made in the repository that information `reflog` command gives us.
19 |
20 | - You can get the hash value from the `git reflog` command as we already see in the previous process.
21 |
22 | ```
23 | $ git reset --hard 8ad5
24 | ```
25 |
26 | - After this repository has been set into the previous state.
27 |
28 | - You can see that `git reflog` status also changed.
29 |
30 | ```
31 | $ git reflog
32 | ```
33 |
34 | - `git log` and `git reflog` may look smiliar. `git log` will show you only information about the commits not the status about repository that `git reflog` does.
35 |
36 | ```
37 | $ git log
38 |
39 | $ git reflog
40 | ```
41 | 
42 |
--------------------------------------------------------------------------------
/docs/06-Resetting-and-Reverting/06-Understanding-GIT.md:
--------------------------------------------------------------------------------
1 | # Understanding GIT
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/understanding-git/)
3 |
4 | 
5 |
6 |
7 | - We have seen that how we can interact with the Git. Now let's take a look , how Git actually works.
8 | - Git is nothing more than a key-value store. When we add a file to the commit, the contents of the file are hashed using the shell one algorithm. The hashed is then used as a key name for the directory and stores the file using that key name.
9 |
10 | - Git has `porcelain` command and `plumbing` command.
11 |
12 | ## Porcelain Commands
13 | - Porcelain commands are commands like `git add`, `git commit`, `git status`. They are easy for user to remember.
14 |
15 | ### git add
16 | - To add a file to the staging area.
17 |
18 | ```
19 | $ git add first_story.txt
20 | ```
21 |
22 | ### git status
23 | - To show the status of the untracked files. Untracked files are files that are not added to the git.
24 |
25 | ```
26 | $ git status
27 | ```
28 |
29 | ### git commit
30 | - To commit the changes.
31 |
32 | ```
33 | $ git commit -m 'First Story'
34 | ```
35 |
36 |
37 | ### git stash
38 | - We can stash all changes in the working area with `git stash` command. Modification in the working area, all get added to the stash.
39 |
40 | ```
41 | $ git stash
42 | ```
43 |
44 | ## Plumbing Commands
45 |
46 | - With the `plumbing` commands, we can access the internals of the git.
47 |
48 | ### git hash-object
49 | - It's hashed the contents of the file. First two character of the hash is used as the key. This is the name of the directory that's store the contents of the file.
50 |
51 | ```
52 | $ git hash-object doc.txt
53 |
54 | e965047ad7c57865823c7d992b1d046ea66edf7
55 |
56 | $ ls ./.git/objects/
57 | 01 0b e6 e9 info pack
58 | ```
59 |
60 | ### git cat-file
61 | - With this plumbing command, we can see the contents of the hashed. Used **-p** flag to print the contents. Use first couple of characters of the complete hash.
62 |
63 | ```
64 | $ git cat-file -p e96504
65 |
66 | Git Story
67 | ```
68 | ### git ls-files
69 | - With this command, we can list all the files of the specific branch.
70 |
71 | ```
72 | $ git ls-files
73 |
74 | lion-and-mouse.txt
75 | foxes-and-oxes.txt
76 | tiger-and-lion.txt
77 | ```
78 |
79 | ### Git Object Contents
80 | - It can be three different object types.
81 |
82 | a.) **commit** - It's a simple commit.
83 |
84 | b.) **tree** - tree is a directory in your file system. It's associated with that repository.
85 |
86 | c.) **blob** - It's just a piece of data. It's not a directory nor a commit.
--------------------------------------------------------------------------------
/docs/06-Resetting-and-Reverting/07-Conclusion.md:
--------------------------------------------------------------------------------
1 | # Conclusion
2 | - Take me to [Video Tutorial](https://kodekloud.com/topic/conclusion/)
3 |
4 | - In this session, we will take a quick recap of all the concepts that we learned.
5 |
6 | #### git install
7 | - Git installing with the software package manager **brew**.
8 |
9 | ```
10 | $ brew install git
11 | ```
12 |
13 | #### git init
14 | - After initialize it git-beginner directory with `git init` command. Git uses to store data.
15 |
16 | ```
17 | $ git init
18 | Initialized empty Git repository in /root/git-beginner/.git/
19 | ```
20 | #### git remote
21 | - We also covered, how we can initialize our remote repository to save our data in the remote server.
22 |
23 | ```
24 | $ git remote add origin https://.../.../[name].git
25 | ```
26 |
27 | #### git push
28 | - We also learned about how we can push our data into the remote repository.
29 |
30 | ```
31 | $ git push origin master
32 | ```
33 |
34 | #### git clone
35 | - We saw that how we can clone remote repository data into our local machine.
36 |
37 | ```
38 | $ git clone https://.../.../[name].git
39 | ```
40 |
41 | #### git branch
42 | - We can work on our own version of the project by creating a new branch.
43 |
44 | ```
45 | $ git branch checkout -b
46 | ```
47 |
48 | #### git commit
49 | - To commit the changes.
50 |
51 | ```
52 | $ git commit -m 'First commit'
53 | ```
54 |
55 | #### git merge
56 | - To merge the commit changes into the other branch.
57 |
58 | ```
59 | $ git merge feature
60 | ```
61 |
62 | #### git rebase
63 | - `git rebase` command creates a different GIT history compare to merging.
64 |
65 | ```
66 | $ git rebase master
67 | ```
68 | - We also learned interactive rebasing, to get more control over the commits that we are rebasing. It will change the commits before rebasing them.
69 |
70 | ```
71 | $ git rebase -i HEAD~4
72 | ```
73 | #### git revert
74 | - We also saw how we could do undo changes. We have to write a couple of characters of commit hash id.
75 |
76 | ```
77 | $ git revert 8ad58
78 | ```
79 |
80 | #### git reset
81 | - `git reset` is a bit harsh. If we reset with `--soft` flag changes still available in the working area and if we do with `--hard` flag, it will remove the changes forever.
82 |
83 | ```
84 | $ git reset --soft HEAD~1
85 |
86 | $ git reset --hard HEAD~1
87 | ```
88 | ##### We also learned how we could open the pull request in the Github platform, where's your team members can review your work.
89 |
90 | ##### Git is an extremely powerful tool. I hope this course has given you a Git introduction of the main concepts.
--------------------------------------------------------------------------------
/images/README.md:
--------------------------------------------------------------------------------
1 | Images goes here
2 |
--------------------------------------------------------------------------------
/images/ffb.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/ffb.PNG
--------------------------------------------------------------------------------
/images/frk.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/frk.PNG
--------------------------------------------------------------------------------
/images/fth1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/fth1.PNG
--------------------------------------------------------------------------------
/images/fth2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/fth2.PNG
--------------------------------------------------------------------------------
/images/g1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/g1.PNG
--------------------------------------------------------------------------------
/images/g2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/g2.PNG
--------------------------------------------------------------------------------
/images/g3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/g3.PNG
--------------------------------------------------------------------------------
/images/g4.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/g4.PNG
--------------------------------------------------------------------------------
/images/g5.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/g5.PNG
--------------------------------------------------------------------------------
/images/g6.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/g6.PNG
--------------------------------------------------------------------------------
/images/g7.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/g7.PNG
--------------------------------------------------------------------------------
/images/git.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/git.PNG
--------------------------------------------------------------------------------
/images/gitlog.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/gitlog.PNG
--------------------------------------------------------------------------------
/images/gitlog1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/gitlog1.PNG
--------------------------------------------------------------------------------
/images/initgit.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/initgit.PNG
--------------------------------------------------------------------------------
/images/initgit1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/initgit1.PNG
--------------------------------------------------------------------------------
/images/initgit2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/initgit2.PNG
--------------------------------------------------------------------------------
/images/mc.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/mc.PNG
--------------------------------------------------------------------------------
/images/mc1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/mc1.PNG
--------------------------------------------------------------------------------
/images/mc2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/mc2.PNG
--------------------------------------------------------------------------------
/images/mc3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/mc3.PNG
--------------------------------------------------------------------------------
/images/nfb.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/nfb.PNG
--------------------------------------------------------------------------------
/images/pull1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/pull1.PNG
--------------------------------------------------------------------------------
/images/pull2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/pull2.PNG
--------------------------------------------------------------------------------
/images/pull3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/pull3.PNG
--------------------------------------------------------------------------------
/images/r1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/r1.PNG
--------------------------------------------------------------------------------
/images/r2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/r2.PNG
--------------------------------------------------------------------------------
/images/r3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/r3.PNG
--------------------------------------------------------------------------------
/images/sshlink.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/sshlink.PNG
--------------------------------------------------------------------------------
/images/sshlink1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/sshlink1.PNG
--------------------------------------------------------------------------------
/images/sshlink2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/sshlink2.PNG
--------------------------------------------------------------------------------
/images/sshlink3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/sshlink3.PNG
--------------------------------------------------------------------------------
/images/t1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/t1.PNG
--------------------------------------------------------------------------------
/images/x1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/x1.PNG
--------------------------------------------------------------------------------
/images/x2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/x2.PNG
--------------------------------------------------------------------------------
/images/x3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kodekloudhub/git-for-beginners-course/5680b6af809d2d80ee1890bfa5fbb5797e51f6fd/images/x3.PNG
--------------------------------------------------------------------------------