Git and Gitlab: Chapter 1 Intoruction To Git Local Chapter 2 Using Git and Gitlab Remote Repositories
Git and Gitlab: Chapter 1 Intoruction To Git Local Chapter 2 Using Git and Gitlab Remote Repositories
git –version
1
CREATING A GIT REPOSITORY
D:\>mkdir sample
D:\>cd sample
D:\sample>git init
D:\sample>git status
On branch master
Initial commit
D:\sample>git commit
On branch master
Initial commit
nothing to commit
D:\sample>git status
On branch master
Initial commit
Untracked files:
print.sh
nothing added to commit but untracked files present (use "git add" to track)
D:\sample>git add print.sh or git add . (to add all files that has been added newly)
2
D:\sample>git status
On branch master
No commits yet
Changes to be committed:
(use "git rm –cached <file>..." to unstage) OR (use "git reset HEAD <file>..." to unstage)
D:\sample>git status
On branch master
Unstaging Changes
use "git rm –cached <file>..." to unstage) OR use "git reset HEAD <file>..." to unstage
D:\sample>git log
commit 4c4521ccdb8946b187b9a0cbf8833a7ef025fcb1
3
To view more details from git log use patch
commit 4c4521ccdb8946b187b9a0cbf8833a7ef025fcb1
index 0000000..ff8ffb1
--- /dev/null
+++ b/print.sh
@@ -0,0 +1 @@
+echo Kiranjit
git status Tells you the current status of the Git repository
git init Create a new empty Git repository
git add Stage changes for commit
git commit -m “Msg” Commit staged changes
git log Shows history of changes
COMMITING A FOLDER
D:\sample>mkdir temp
When we create empty folder we will not be able to commit as it is empty. We should insert one
empty file name “.gitkeep” and then git will recognize for staging and commit.
temp/
nothing added to commit but untracked files present (use "git add" to track)
4
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git add .
DELETING FILES
If the files are not tracked then we can simply do a rm command but if it is already staged and
committed to git repo then we have to again add to stage and commit after doing a rm.
If I do not want to make some files or folder not to be considered by git repository.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ mkdir config
config/
nothing added to commit but untracked files present (use "git add" to track)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
5
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
CREATING BRANCH
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
nothing to commit, working directory clean
modified: print.sh
no changes added to commit (use "git add" and/or "git commit -a")
6
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git branch
feature/dev
* master
MERGING A BRANCH
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git branch -d feature/dev
error: The branch 'feature/dev' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature/dev'.
commit fccab4140ff4495726f05aa35f9175c6c5addcf1
Author: Kiranjit Parida <[email protected]>
Date: Sun Aug 22 08:24:55 2021 +0530
commit 5a8bfbf8595c2262e6a5095a0d8417ee623e212e
Author: Kiranjit Parida <[email protected]>
Date: Sun Aug 22 08:13:04 2021 +0530
commit 09dbd7de3a6bd407c5dd050bc0fa050aea61f506
Author: Kiranjit Parida <[email protected]>
Date: Sun Aug 22 07:55:43 2021 +0530
commit 4c4521ccdb8946b187b9a0cbf8833a7ef025fcb1
Author: Kiranjit Parida <[email protected]>
Date: Sat Aug 21 22:28:28 2021 +0530
Once we merge the changes to Master then we can delete the feature/dev branch.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git branch -d feature/dev
Deleted branch feature/dev (was fccab41).
ADVANCED MERGING
If my feature/dev branch and master branch data are not same then we can not do a fast forward
merge. This happens when we made some changes to master and dev as well.
REBASING COMMIT
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git init
Initialized empty Git repository in D:/sample/.git/
7
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ clear
Initial commit
8
Date: Sun Aug 22 10:27:30 2021 +0530
commit 031d5d2282ca62185c64713492194202346edc7b
Author: paridk <[email protected]>
Date: Sun Aug 22 10:28:08 2021 +0530
Added test3.txt to master Take latest change from Master first even though
it was added later after test2.txt file from bugfix/dev branch
commit 8dd56607c602d35e381520d50df716e4237cbd0d
Author: paridk <[email protected]>
Date: Sun Aug 22 10:26:31 2021 +0530
https://www.atlassian.com/git/tutorials/merging-vs-rebasing
Merge Commits:
This creates a new “merge commit” in the feature branch that ties together the histories of both
branches, giving you a branch structure that looks like this.
9
MERGE CONFLICT
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ ls
index.html
10
1 file changed, 1 insertion(+), 1 deletion(-)
If you open the file in any editor or visual code you will have option to accept
the changes or even compare. We have accepted the incoming changes i.e., the
changes which we did in feature/dev branch.
11
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master|MERGING)
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
no changes added to commit (use "git add" and/or "git commit -a")
3. Click on blank Project creation and fill the necessary details -> Finally click on Create Project
Button.
12
4. We have to generate SSH to push and pull the code from GitLab repo.
1. Now go to the local folder you want to push to remote repo and do a git init,add and commit
the changes. In my case Local Folder name is Renolytix.
2. git remote add origin [email protected]:renolytix/renolytix.git
3. git push -u origin –all
4. refresh the gitlab page and you will see the project pushed from local to
remote repo. (Master branch)
13
CLONING A REMOTE REPOSITORY
GITLAB UI
RESOLVING CONFLICTS
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ vi ReadMe.txt
(add one line in the last)
14
https://wallpapersafari.com/w/C08EIk
sample
Line Added extra Line added
modified: ReadMe.txt
no changes added to commit (use "git add" and/or "git commit -a")
Now also make some changes from remote repo directly and commit there.
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <[email protected]>
Date: Thu Aug 26 11:05:15 2021 +0530
15
2d4229a..1fc062e master -> origin/master
Auto-merging ReadMe.txt
CONFLICT (content): Merge conflict in ReadMe.txt
Automatic merge failed; fix conflicts and then commit the result.
commit 1fc062e1c4b3c9bb35f13bd03d64a895124a287a
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 06:51:33 2021 +0000
removed sample line from remote See your remote changes are showing up in
log but local changes are not showing
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <[email protected]>
Date: Thu Aug 26 11:05:15 2021 +0530
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <[email protected]>
Date: Thu Aug 26 11:05:15 2021 +0530
now add the changes again to local and push followed by a commit since local changes are now
gone.
16
(Make some changes)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
no changes added to commit (use "git add" and/or "git commit -a")
Now also make some changes from remote repo directly and commit there.
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
17
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
no changes added to commit (use "git add" and/or "git commit -a")
commit 1fc062e1c4b3c9bb35f13bd03d64a895124a287a
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 06:51:33 2021 +0000
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <[email protected]>
Date: Thu Aug 26 11:05:15 2021 +0530
Unmerged paths:
(use "git add <file>..." to mark resolution)
commit c6729f68eaea64a24ec62d364541233ff16feb5f
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 07:04:34 2021 +0000
commit 1fc062e1c4b3c9bb35f13bd03d64a895124a287a
18
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 06:51:33 2021 +0000
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <[email protected]>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <[email protected]>
Date: Thu Aug 26 11:05:15 2021 +0530
modified: ReadMe.txt
no changes added to commit (use "git add" and/or "git commit -a")
19
remote: https://gitlab.com/renolytix/renolytix/-/merge_requests/new?merge_request
%5Bsource_branch%5D=feature%2Fdev
remote:
To [email protected]:renolytix/renolytix.git
* [new branch] feature/dev -> feature/dev
Got to Repository from UI and you will see a option to create merge request.
Click on that and again hit same inside the page.
Then Click on MERGE (or REBASE if we want to fix the remote changes as well)
20
So our feature branch changes has been Merged with source (Master).
21