Git and GitLab
VCS version Control System
git –version
CHAPTER 1 INTORUCTION TO GIT LOCAL
CHAPTER 2 USING GIT AND GITLAB REMOTE REPOSITORIES
CHAPTER 1 INTORUCTION TO GIT LOCAL
1
CREATING A GIT REPOSITORY
D:\>mkdir sample
D:\>cd sample
D:\sample>git init
Initialized empty Git repository in D:/sample/.git/
D:\sample>git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
D:\sample>git config --global user.name "Kiranjit Parida"
D:\sample>git config --global user.email “kiranjit4u@gmail.com”
YOUR FIRST GIT COMMIT
D:\sample>git commit
On branch master
Initial commit
nothing to commit
Now create a file “print.sh” for committing
D:\sample>git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
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)
new file: print.sh
D:\sample>git commit -m "Commiting my first script"
[master (root-commit) 4c4521c] Commiting my first script
1 file changed, 1 insertion (+)
create mode 100644 print.sh
D:\sample>git status
On branch master
nothing to commit, working directory clean
Unstaging Changes
use "git rm –cached <file>..." to unstage) OR use "git reset HEAD <file>..." to unstage
Viewing Changes with git log
D:\sample>git log
commit 4c4521ccdb8946b187b9a0cbf8833a7ef025fcb1
Author: Kiranjit Parida <kiranjit4u@gmail.com>
Date: Sat Aug 21 22:28:28 2021 +0530
Commiting my first script
3
To view more details from git log use patch
D:\sample>git log --patch
commit 4c4521ccdb8946b187b9a0cbf8833a7ef025fcb1
Author: Kiranjit Parida <kiranjit4u@gmail.com>
Date: Sat Aug 21 22:28:28 2021 +0530
Commiting my first script
diff --git a/print.sh b/print.sh
new file mode 100644
index 0000000..ff8ffb1
--- /dev/null
+++ b/print.sh
@@ -0,0 +1 @@
+echo Kiranjit
\ No newline at end of file
BASIC GIT COMMAND SUMMARY
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.
<OPEN GIT BASH CLI>
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
nothing to commit, working directory clean
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ touch temp/.gitkeep
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
temp/
nothing added to commit but untracked files present (use "git add" to track)
4
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: temp/.gitkeep
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git commit -m "Adding empty folder"
[master 09dbd7d] Adding empty folder
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 temp/.gitkeep
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.
THE .gitignore FILE
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
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ touch config/private.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
config/
nothing added to commit but untracked files present (use "git add" to track)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ vim .gitignore
(Add config/ inside the gitignore file)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ ls -l
total 1
drwxr-xr-x 1 RENU 197121 0 Aug 22 08:10 config/
-rw-r--r-- 1 RENU 197121 13 Aug 21 22:24 print.sh
drwxr-xr-x 1 RENU 197121 0 Aug 22 07:55 temp/
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git commit -m "Added gitignore configuration"
[master 5a8bfbf] Added gitignore configuration
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
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
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git checkout -b feature/dev
Switched to a new branch 'feature/dev'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ ls
config/ print.sh temp/
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ cat "This is another line" >> print.sh
cat: 'This is another line': No such file or directory
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ echo "\necho 'This is another line'" >> print.sh
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ cat print.sh
echo Kiranjit
echo 'This is another line'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git staus
git: 'staus' is not a git command. See 'git --help'.
Did you mean this?
status
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git status
On branch feature/dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: print.sh
no changes added to commit (use "git add" and/or "git commit -a")
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git commit -m "Added another echo inside print.sh"
[feature/dev warning: LF will be replaced by CRLF in print.sh.
The file will have its original line endings in your working directory.
fccab41] Added another echo inside print.sh
warning: LF will be replaced by CRLF in print.sh.
The file will have its original line endings in your working directory.
1 file changed, 2 insertions(+), 1 deletion(-)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git checkout master
Switched to branch 'master'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
nothing to commit, working directory clean
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ ls
config/ print.sh temp/
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ cat print.sh
echo Kiranjit
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
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'.
$ git branch -D feature/dev [Forcefully]
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git checkout master
Already on 'master'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git merge feature/dev
Updating 5a8bfbf..fccab41
Fast-forward
print.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git log
commit fccab4140ff4495726f05aa35f9175c6c5addcf1
Author: Kiranjit Parida <kiranjit4u@gmail.com>
Date: Sun Aug 22 08:24:55 2021 +0530
Added another echo inside print.sh
commit 5a8bfbf8595c2262e6a5095a0d8417ee623e212e
Author: Kiranjit Parida <kiranjit4u@gmail.com>
Date: Sun Aug 22 08:13:04 2021 +0530
Added gitignore configuration
commit 09dbd7de3a6bd407c5dd050bc0fa050aea61f506
Author: Kiranjit Parida <kiranjit4u@gmail.com>
Date: Sun Aug 22 07:55:43 2021 +0530
Adding empty folder
commit 4c4521ccdb8946b187b9a0cbf8833a7ef025fcb1
Author: Kiranjit Parida <kiranjit4u@gmail.com>
Date: Sat Aug 21 22:28:28 2021 +0530
Commiting my first script
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
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ touch test1.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git commit -m "Added file test1.txt to master"
[master (root-commit) 8dd5660] Added file test1.txt to master
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test1.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git checkout -b bugfix/dev
Switched to a new branch 'bugfix/dev'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ ls
test1.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ touch test2.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ git commit -m "Added file test2.txt to dev branch"
[bugfix/dev 41c1ef2] Added file test2.txt to dev branch
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test2.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ git checkout master
Switched to branch 'master'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ touch test3.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git commit -m "Added test3.txt to master"
[master 031d5d2] Added test3.txt to master
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test3.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git checkout bugfix/dev
Switched to branch 'bugfix/dev'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ ls
test1.txt test2.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: Added file test2.txt to dev branch
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (bugfix/dev)
$ git log
commit 1893fdd6438ecd1e579cb5fc28939f2c1421d092
Author: paridk <kiranjit.parida@gs.com>
8
Date: Sun Aug 22 10:27:30 2021 +0530
Added file test2.txt to dev branch consider this change as final
commit 031d5d2282ca62185c64713492194202346edc7b
Author: paridk <kiranjit.parida@gs.com>
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 <kiranjit.parida@gs.com>
Date: Sun Aug 22 10:26:31 2021 +0530
Added file test1.txt to master Initial
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.
Rebase option: (Alternative to Merge)
This moves the entire feature branch to begin on the tip of the main branch, effectively
incorporating all of the new commits in main. But, instead of using a merge commit, rebasing re-
writes the project history by creating brand new commits for each commit in the original branch.
9
MERGE CONFLICT
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ ls
index.html
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ cat index.html
<html>
<head>
<title>Sample Website<title>
</head>
<body>
Hi this is me
</body>
</html>
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git checkout feature/dev
Switched to branch 'feature/dev'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ ls
index.html
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ cat index.html
<html>
<head>
<title>Sample Website<title>
</head>
<body>
Hi this is me
</body>
</html>
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ vi index.html
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ cat index.html
<html>
<head>
<title>SampleWebsite<title>
</head>
<body>
Hi this is me and I am Kiranjit
</body>
</html>
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git commit -m "updated the line 6"
[feature/dev 7ec1add] updated the line 6
10
1 file changed, 1 insertion(+), 1 deletion(-)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git checkout master
Switched to branch 'master'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ vi index.html
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ cat index.html
<html>
<head>
<title>Sample Website<title>
</head>
<body>
Hi this is me
And I am Master
</body>
</html>
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git commit -m "added new line 7"
[master 734017e] added new line 7
1 file changed, 1 insertion(+)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git checkout feature/dev
Switched to branch 'feature/dev'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git merge master
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev|MERGING)
$ git merge --abort
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ vi index.html
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (feature/dev)
$ git checkout master
Switched to branch 'master'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ vi index.html
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master)
$ git merge feature/dev
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master|MERGING)
$ vi index.html
<html>
<head>
<title>SampleWebsite<title>
</head>
<body>
<<<<<<< HEAD This is what master repo has the new changes
Hi this is me
And I am Master
=======
Hi this is me and I am Kiranjit
>>>>>>> feature/dev This is what feature/dev repo has the new changes
</body>
</html>
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)
both modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master|MERGING)
$ cat index.html
<html>
<head>
<title>Sample Website<title>
</head>
<body>
Hi this is me and I am Kiranjit
</body>
</html>
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master|MERGING)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/sample (master|MERGING)
$ git commit -m "Edited and change done to file"
[master 4a73fd3] Edited and change done to file
CHAPTER 2 USING GIT AND GITLAB REMOTE REPOSITORIES
WORKING WITH REMOTE REPOSITORY
1. Sign in to GitLab.com (register if you are new user)
2. Create a New Project
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.
C:\Users\RENU>ssh-keygen -t ed25519 -C "My Gitlab ssh"
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\RENU/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase): <type empty>
Enter same passphrase again: <type empty>
Your identification has been saved in C:\Users\RENU/.ssh/id_ed25519.
Your public key has been saved in C:\Users\RENU/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:HdaYdzDPKyTfAfpS8bIbvNyJKcUujpd1Z6cVgpiyVxY My Gitlab ssh
The key's randomart image is:
+--[ED25519 256]--+
| = |
| EO |
| XO* |
| .=#*+|
| S = X + .|
| . . =.O..=|
| . ooB.o=.|
| ooo . |
| ... |
+----[SHA256] -----+
PUSH TO REMOTE REPOSITORY
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 git@gitlab.com: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
Git clone https://gitlab.com/renolytix/renolytix.git
PULL FROM REMOTE REPOSITORY
$ git pull origin
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
Already up-to-date.
(Since there are no changes)
GITLAB UI
RESOLVING CONFLICTS
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ vi ReadMe.txt
(add one line in the last)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ cat ReadMe.txt
https://getbootstrap.com/
14
https://wallpapersafari.com/w/C08EIk
sample
Line Added extra Line added
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ReadMe.txt
no changes added to commit (use "git add" and/or "git commit -a")
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git add ReadMe.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git commit -m "Line Added from local"
[master ec90c71] Line Added from local
1 file changed, 1 insertion(+)
Now also make some changes from remote repo directly and commit there.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git log
commit ec90c716a2ac7fd06c17a22f54dbf901d740da44
Author: paridk <kiranjit.parida@gs.com>
Date: Thu Aug 26 12:20:57 2021 +0530
Line Added from local
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <kiranjit.parida@gs.com>
Date: Thu Aug 26 11:05:15 2021 +0530
pushing the original files
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git push origin master
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
remote:
remote: INFO: Your SSH key is expiring soon. Please generate a new key.
remote:
To git@gitlab.com:renolytix/renolytix.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to
'git@gitlab.com:renolytix/renolytix.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git pull origin master
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
remote:
remote: INFO: Your SSH key is expiring soon. Please generate a new key.
remote:
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From gitlab.com:renolytix/renolytix
* branch master -> FETCH_HEAD
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.
So how to resolve this :-
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master|MERGING)
$ git reset --hard origin/master
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git log
commit 1fc062e1c4b3c9bb35f13bd03d64a895124a287a
Author: kiranjit parida <kiranjit4u@gmail.com>
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 <kiranjit4u@gmail.com>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <kiranjit.parida@gs.com>
Date: Thu Aug 26 11:05:15 2021 +0530
pushing the original files
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git pull --rebase
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
Current branch master is up to date.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git log
commit 1fc062e1c4b3c9bb35f13bd03d64a895124a287a
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 06:51:33 2021 +0000
removed sample line from remote
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <kiranjit.parida@gs.com>
Date: Thu Aug 26 11:05:15 2021 +0530
pushing the original files
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
now add the changes again to local and push followed by a commit since local changes are now
gone.
Another way to do the same without losing the local changes
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ vi ReadMe.txt
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)
both modified: ReadMe.txt
no changes added to commit (use "git add" and/or "git commit -a")
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git commit -m "changes from local"
[master e755614] changes from local
1 file changed, 1 insertion(+), 1 deletion(-)
Now also make some changes from remote repo directly and commit there.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git push origin master
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
remote:
remote: INFO: Your SSH key is expiring soon. Please generate a new key.
remote:
To git@gitlab.com:renolytix/renolytix.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@gitlab.com:renolytix/renolytix.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git pull origin master --rebase
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
remote:
remote: INFO: Your SSH key is expiring soon. Please generate a new key.
remote:
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From gitlab.com:renolytix/renolytix
* branch master -> FETCH_HEAD
1fc062e..c6729f6 master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: changes from local
Using index info to reconstruct a base tree...
M ReadMe.txt
Falling back to patching base and 3-way merge...
Auto-merging ReadMe.txt
CONFLICT (content): Merge conflict in ReadMe.txt
error: Failed to merge in the changes.
Patch failed at 0001 changes from local
The copy of the patch that failed is found in: .git/rebase-apply/patch
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".
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master|REBASE 1/1)
$ git status
rebase in progress; onto c6729f6
You are currently rebasing branch 'master' on 'c6729f6'.
(fix conflicts and then run "git rebase --continue")
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)
both modified: ReadMe.txt
no changes added to commit (use "git add" and/or "git commit -a")
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master|REBASE 1/1)
$ git log
commit c6729f68eaea64a24ec62d364541233ff16feb5f
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 07:04:34 2021 +0000
changes from remote
commit 1fc062e1c4b3c9bb35f13bd03d64a895124a287a
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 06:51:33 2021 +0000
removed sample line from remote
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <kiranjit.parida@gs.com>
Date: Thu Aug 26 11:05:15 2021 +0530
pushing the original files
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master|MERGING)
$ 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)
both modified: ReadMe.txt Again we will see the local changes
uncommitted
no changes added to commit (use "git add" and/or "git commit -a")
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master|REBASE 1/1)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master|REBASE 1/1)
$ git commit -m "changes from local"
[detached HEAD 65abc38] changes from local
1 file changed, 4 insertions(+)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master|REBASE 1/1)
$ git log
commit 65abc3869183d3dbafd2577b362ba71ecd854d77
Author: paridk <kiranjit.parida@gs.com>
Date: Thu Aug 26 12:36:29 2021 +0530
changes from local Local Changes now appearing
commit c6729f68eaea64a24ec62d364541233ff16feb5f
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 07:04:34 2021 +0000
changes from remote
commit 1fc062e1c4b3c9bb35f13bd03d64a895124a287a
18
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 06:51:33 2021 +0000
removed sample line from remote
commit 2d4229a9ae759ae67ecc44062cecce2909211a80
Author: kiranjit parida <kiranjit4u@gmail.com>
Date: Thu Aug 26 05:58:35 2021 +0000
Update ReadMe.txt
commit 07bf844cf49448abcb1c8fce9866a1b60b06a4a6
Author: paridk <kiranjit.parida@gs.com>
Date: Thu Aug 26 11:05:15 2021 +0530
pushing the original files
WORKING WITH MERGE REQUESTS
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git pull origin master
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
remote:
remote: INFO: Your SSH key is expiring soon. Please generate a new key.
remote:
From gitlab.com:renolytix/renolytix
* branch master -> FETCH_HEAD
Already up-to-date.
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (master)
$ git checkout -b feature/dev
Switched to a new branch 'feature/dev'
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (feature/dev)
$ git status
On branch feature/dev
nothing to commit, working directory clean
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (feature/dev)
$ vi ReadMe.txt
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (feature/dev)
$ git status
On branch feature/dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ReadMe.txt
no changes added to commit (use "git add" and/or "git commit -a")
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (feature/dev)
$ git add .
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (feature/dev)
$ git commit -m "Updated the ReadMe.txt"
[feature/dev b229899] Updated the ReadMe.txt
1 file changed, 1 insertion(+), 3 deletions(-)
RENU@LAPTOP-S1ERAA8G MINGW64 /d/renolytix (feature/dev)
$ git push origin feature/dev
Enter passphrase for key '/c/Users/RENU/.ssh/id_ed25519':
remote:
remote: INFO: Your SSH key is expiring soon. Please generate a new key.
remote:
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 993 bytes | 0 bytes/s, done.
Total 9 (delta 4), reused 0 (delta 0)
remote:
remote: To create a merge request for feature/dev, visit:
19
remote: https://gitlab.com/renolytix/renolytix/-/merge_requests/new?merge_request
%5Bsource_branch%5D=feature%2Fdev
remote:
To git@gitlab.com: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)
Finally, we will get the below snap: -
20
So our feature branch changes has been Merged with source (Master).
21