0% found this document useful (0 votes)
15 views

Using_Git

How to use Git

Uploaded by

Ken Jo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Using_Git

How to use Git

Uploaded by

Ken Jo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Using Git

Install git for windows with all default settings

cambi@DESKTOP-SBUVAQV MINGW64 ~

$ git --version
git version 2.46.2.windows.1

cambi@DESKTOP-SBUVAQV MINGW64 ~

$ mkdir test-website

cambi@DESKTOP-SBUVAQV MINGW64 ~

$ cd test-website/

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website

$ git status
fatal: not a git repository (or any of the parent directories): .git

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website

$ git init

Initialized empty Git repository in C:/Users/cambi/test-website/.git/

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ dir -a
. .. .git

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git config --global user.email "[email protected]"

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ vim readme.md

Note: Once the document opens, press ‘i’ to insert test and type Hello World!

When done, press ESC followed by ‘:x’ to save and exit

(To exit without saving type ‘:q!’)


cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ dir -a

. .. .git readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.md

nothing added to commit but untracked files present (use "git add" to track)
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git add readme.md

warning: in the working copy of 'readme.md', LF will be replaced by CRLF the


next time Git touches it

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit

Aborting commit due to empty commit message.

Note: vim will open with messages referring to commit. Simply press ESC
followed by ‘:x’. You should then see the message above.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "My first commit!"


[master (root-commit) a2cb6e3] My first commit!
1 file changed, 1 insertion(+)
create mode 100644 readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ git status
On branch master
nothing to commit, working tree clean

Working with Multiple Files


# Create a new file

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ vim index.html

# Modify the existing file by adding a new line such as ‘I am learning git.”

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ vim readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.md

Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html

no changes added to commit (use "git add" and/or "git commit -a")
# Add all files in current directory

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ git add .
warning: in the working copy of 'readme.md', LF will be replaced by CRLF the
next time Git touches it
warning: in the working copy of 'index.html', LF will be replaced by CRLF the
next time Git touches it

# Can also choose to enter $ git add –all instead of $ git add .

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html
modified: readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git reset HEAD readme.md


Unstaged changes after reset:
M readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "added first page"


[master addf0b1] added first page
1 file changed, 5 insertions(+)
create mode 100644 index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.md

no changes added to commit (use "git add" and/or "git commit -a")

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git add .

warning: in the working copy of 'readme.md', LF will be replaced by CRLF the


next time Git touches it

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "Improve readme"


[master 702bdad] Improve readme
1 file changed, 1 insertion(+)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
nothing to commit, working tree clean
Using Log Files

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git log
commit 702bdadddb356098fa8a51b1e45b689d6462ad8c (HEAD ->
master)
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:18:14 2024 -0700

Improve readme

commit addf0b15f8e644ef830377d8cb2c2b6ee910ca9a
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:16:22 2024 -0700

added first page

commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700

My first commit!

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git log --patch

commit 702bdadddb356098fa8a51b1e45b689d6462ad8c (HEAD ->


master)
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:18:14 2024 -0700
Improve readme

diff --git a/readme.md b/readme.md


index 81ffa8e..d64bc26 100644
--- a/readme.md
+++ b/readme.md
@@ -1 +1,2 @@
Hello, this is my first commit.
+I am leaning Git.

commit addf0b15f8e644ef830377d8cb2c2b6ee910ca9a
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:16:22 2024 -0700

added first page

diff --git a/index.html b/index.html


new file mode 100644
:
commit 702bdadddb356098fa8a51b1e45b689d6462ad8c (HEAD ->
master)
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:18:14 2024 -0700

Improve readme

diff --git a/readme.md b/readme.md


index 81ffa8e..d64bc26 100644
--- a/readme.md
+++ b/readme.md
@@ -1 +1,2 @@
Hello, this is my first commit.
+I am leaning Git.

commit addf0b15f8e644ef830377d8cb2c2b6ee910ca9a
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:16:22 2024 -0700

added first page


diff --git a/index.html b/index.html
new file mode 100644
index 0000000..4449aff
--- /dev/null
+++ b/index.html
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ <h1>My website</h1>
+ </body>
+</html>

commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700

My first commit!

diff --git a/readme.md b/readme.md


new file mode 100644
index 0000000..81ffa8e
--- /dev/null
+++ b/readme.md
@@ -0,0 +1 @@
+Hello, this is my first commit.
(END)

Note: Type ‘:q’ to exit

Working with Folders


Note: Git only tracks files, not folders.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ mkdir temp
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ dir -a
. .. .git index.html readme.md temp

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
nothing to commit, working tree clean

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ touch temp\.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
temp.gitkeep

nothing added to commit but untracked files present (use "git add" to track)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git add .

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: temp.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ git commit -m "Added temp folder"
[master 70634b5] Added temp folder
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 temp.gitkeep

Deleting Files
For untracked files:

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ touch newfile.txt

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ dir -a
. .. .git index.html newfile.txt readme.md temp temp.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
newfile.txt

nothing added to commit but untracked files present (use "git add" to track)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ rm newfile.txt

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
nothing to commit, working tree clean

For tracked files:


cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ dir -a
. .. .git index.html readme.md temp temp.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ rm -rf -- temp

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ dir -a
. .. .git index.html readme.md temp.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
nothing to commit, working tree clean

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ rm -rf -- temp.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: temp.gitkeep

no changes added to commit (use "git add" and/or "git commit -a")

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git add .
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: temp.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "Removed temp folder"


[master e851242] Removed temp folder
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 temp.gitkeep

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ dir -a
. .. .git index.html readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git log
commit e8512422632dd98c23475ed22c22bf4acd89d983 (HEAD -> master)
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 09:17:34 2024 -0700

Removed temp folder

commit 70634b50499a77cceb6c1f25452836484176ba21
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 15:34:41 2024 -0700

Added temp folder

commit 702bdadddb356098fa8a51b1e45b689d6462ad8c
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:18:14 2024 -0700
Improve readme

commit addf0b15f8e644ef830377d8cb2c2b6ee910ca9a
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:16:22 2024 -0700

added first page

commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700

My first commit!
(END)

Files inside directory that need to be ignored:

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ mkdir config

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ touch config/private.txt

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (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)
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ vim .gitignore

Note: This file lists all directories or files to be ignored. The config file is then
ignored.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (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)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ dir -a
. .. .git .gitignore config index.html readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ git add .
warning: in the working copy of '.gitignore', LF will be replaced by CRLF the
next time Git touches it

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "Added gitignore configuration"


[master 39ce803] Added gitignore configuration
1 file changed, 1 insertion(+)
create mode 100644 .gitignore

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
nothing to commit, working tree clean

Creating Branches
Main and Master Branch are the same branches

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git checkout -b feature/new-table


Switched to a new branch 'feature/new-table'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ git status
On branch feature/new-table
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)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ dir -a
. .. .git config index.html readme.md
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ vim index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ git add .
warning: in the working copy of 'index.html', LF will be replaced by CRLF the
next time Git touches it

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ git commit -m "Added table"


[feature/new-table e5ab069] Added table
2 files changed, 1 insertion(+)
create mode 100644 config/private.txt

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ cat index.html
<html>
<body>
<h1>My website</h1>
<table></table>
</body>
</html>

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ git checkout master


Switched to branch 'master'
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ cat index.html
<html>
<body>
<h1>My website</h1>
</body>
</html>

# No changes have been made in the master branch

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git checkout feature/new-table


Switched to branch 'feature/new-table'

Fast-Forward Merging and Deleting Branches


cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)
$ git branch -d feature/new-table

error: cannot delete branch 'feature/new-table' used by worktree at


'C:/Users/cambi/test-website'

Note: will protect from mistakenly deleting the branch. To delete the branch
regardless, run the following:

$ git branch -D feature/new-table

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)

$ git checkout master


Switched to branch 'master'
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git merge feature/new-table


Merge made by the 'ort' strategy.
config/private.txt | 0
index.html |1+
2 files changed, 1 insertion(+)
create mode 100644 config/private.txt

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git log
commit 779c471c95b4b7ed85045e08d9c69d615cf2e959 (HEAD -> master)
Merge: 39ce803 e5ab069
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 15:54:39 2024 -0700

Merge branch 'feature/new-table'

commit e5ab069fe7abfecbc61f0bd5e5e0202735baaf48 (feature/new-


table)
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 09:59:45 2024 -0700

Added table

commit 39ce803ff1495ecd784e6fdbb1c686442cee4cfa
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 09:51:02 2024 -0700

Added gitignore configuration

commit e8512422632dd98c23475ed22c22bf4acd89d983
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 09:17:34 2024 -0700

Removed temp folder

commit 70634b50499a77cceb6c1f25452836484176ba21
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 15:34:41 2024 -0700

Added temp folder

commit 702bdadddb356098fa8a51b1e45b689d6462ad8c
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:18:14 2024 -0700

Improve readme

commit addf0b15f8e644ef830377d8cb2c2b6ee910ca9a
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:16:22 2024 -0700

added first page

commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700

My first commit!

Note: mention of merge fast-forward refers to a simple merge. It is only


possible to use it if no other merge requests have been made previously. If
the master changed at some point and is different from the branch, the fast-
forward merge cannot be done.

# Now that the merge was completed, the branch can now be deleted.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git branch -d feature/new-table


Deleted branch feature/new-table (was e5ab069).

Recursive Merging
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git checkout -b bugfix/table


Switched to a new branch 'bugfix/table'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table)

$ vim index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table)

$ git add .

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table)

$ git status
On branch bugfix/table
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table)

$ git commit -m "Added table cell"


[bugfix/table 5f7c802] Added table cell
1 file changed, 5 insertions(+), 1 deletion(-)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table)

$ git checkout master


Switched to branch 'master'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ vim readme.md

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git add .

warning: in the working copy of 'readme.md', LF will be replaced by CRLF the


next time Git touches it

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "Learning branching"


[master 0836e2b] Learning branching
1 file changed, 1 insertion(+), 1 deletion(-)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git merge bugfix/table


Merge made by the 'ort' strategy.
index.html | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

Note: The master branch has moved on, but the bugfix/table branch also
has a commit but based on the previous master branch version. A fast-
forward branch is no longer possible here because it does not have the same
parent.
The message that appears tells GitLab that this is not a fast-forward merge.
The merge was still made, nevertheless. The message at the command line
shows the merge was made by ‘ort’ strategy.

GitHub uses the merge-ort strategy to create merge commits. This


strategy is a relatively new Git merge strategy that is significantly faster and
addresses subtle correctness issues found in the merge-recursive strategy

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git log

Rebasing Commits
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)
$ git checkout -b bugfix/table-2
Switched to a new branch 'bugfix/table-2'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)

$ vim index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)

$ git add .

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)

$ git commit -m "Added 2nd cell"


[bugfix/table-2 c49ad4d] Added 2nd cell
1 file changed, 1 insertion(+)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)

$ git checkout master


Switched to branch 'master'
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ vim readme.md
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git add .
warning: in the working copy of 'readme.md', LF will be replaced by CRLF the
next time Git touches it

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "Learning rebasing"


[master 5694362] Learning rebasing
1 file changed, 1 insertion(+), 1 deletion(-)

Note: Branches are no longer the same so cannot do a fast-forward merge.


Rebasing takes the changes from another branch and adds to the current
branch and then adds our commit.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git checkout bugfix/table-2


Switched to branch 'bugfix/table-2'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)

$ git log
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)

$ git rebase master


Successfully rebased and updated refs/heads/bugfix/table-2.
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)

$ git checkout master


Switched to branch 'master'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git merge bugfix/table-2


Updating 5694362..087ccf4
Fast-forward
index.html | 1 +
1 file changed, 1 insertion(+)

Note: The merge has gone back to being Fast-Forward


Reserving Merge Conflicts
A merge conflict happens when you are trying to merge changes using
merge or rebase. Two different commits may have modified the same line or
file. The system may not understand the change being merged.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git checkout -b bugfix/table-3


Switched to a new branch 'bugfix/table-3'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)


$ vim index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)


$ git add .

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)

$ git commit -m "Rename cell"

[bugfix/table-3 60cc1dd] Rename cell

1 file changed, 2 insertions(+), 2 deletions(-)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)


$ git checkout master
Switched to branch 'master'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ vim index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git add .

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git commit -m "Renamed in My cell"


[master 50380ac] Renamed in My cell
1 file changed, 2 insertions(+), 2 deletions(-)

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git merge bugfix/table-3


Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Note: A conflict was created. This has to be fixed and cannot be left this way.
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)

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")

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ git merge --abort

Note: The merge --abort command will end this conflict. It restores the
master to its original content.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
nothing to commit, working tree clean

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git checkout bugfix/table-3

Switched to branch 'bugfix/table-3'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)

$ git rebase master


Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
error: could not apply 60cc1dd... Rename cell
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --
abort".
hint: Disable this message with "git config advice.mergeConflict false"
Could not apply 60cc1dd... Rename cell

Note: trying to rebase also shows a merge conflict.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)|


REBASE 1/1)

$ git status
interactive rebase in progress; onto 50380ac
Last command done (1 command done):
pick 60cc1dd Rename cell
No commands remaining.
You are currently rebasing branch 'bugfix/table-3' on '50380ac'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)

Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: index.html

no changes added to commit (use "git add" and/or "git commit -a")

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)|


REBASE 1/1)

$ git rebase --abort

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)


$ git status
On branch bugfix/table-3
nothing to commit, working tree clean

Note: This time we will try to resolve the conflict from the merge branch

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-3)

$ git checkout master


Switched to branch 'master'

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git merge bugfix/table-3


Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)

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")
Note: The HEAD corresponds to the conflicts seen in the master branch, and
other branches will be listed as well. This can be resolved by editing this file
and keeping the changes you want.

Opening the project folder in visual studio code:


There will be options to Accept Current Change or Accept Incoming Change
or simply to Compare Changes:
Here we have accepted the incoming change and make a small change and
save all.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)

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")

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ vim index.html
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ git add index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ git status

On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)

Changes to be committed:
modified: index.html

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master|MERGING)

$ git commit -m "Resolve conflict"


[master 10e5fe7] Resolve conflict

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git status
On branch master
nothing to commit, working tree clean

Working with GitLab


Create a GitLab Account and create a new project without a Readme file. The
following are some suggestions after creating a project named test_website.

Git local setup

git config --local user.name "Louis Rey"


git config --local user.email "[email protected]"

Create a new repository (Using SSH)

git clone [email protected]:kenjo138/test_website.git


cd test_website
git switch --create main
touch README.md
git add README.md
git commit -m "add README"
git push --set-upstream origin main

Push an existing folder

cd existing_folder
git init --initial-branch=main
git remote add origin [email protected]:kenjo138/test_website.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin main

Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin [email protected]:kenjo138/test_website.git
git push --set-upstream origin --all
git push --set-upstream origin --tags

We will push an existing folder onto GitLab


To add a new remote where origin is an alias for the git address that follows:

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ git remote add origin [email protected]:kenjo138/test_website.git

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git remote -v
origin [email protected]:kenjo138/test_website.git (fetch)
origin [email protected]:kenjo138/test_website.git (push)

Note: This checks the remote repository

Generate SSH Keys in GitLab


cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/cambi/.ssh/id_ed25519):

Hit Enter to bypass this section

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/cambi/.ssh/id_ed25519):
Created directory '/c/Users/cambi/.ssh'.
Enter passphrase for "/c/Users/cambi/.ssh/id_ed25519" (empty for no
passphrase):

A passphrase is important but we will skip it for now:

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/cambi/.ssh/id_ed25519):
Created directory '/c/Users/cambi/.ssh'.
Enter passphrase for "/c/Users/cambi/.ssh/id_ed25519" (empty for no
passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/cambi/.ssh/id_ed25519
Your public key has been saved in /c/Users/cambi/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:m4TQkFH9UF7VVqYQ58sP8CkYptPQEMxJRpQ36O5gYII
cambi@DESKTOP-SBUVAQV
The key's randomart image is:
+--[ED25519 256]--+
| o+.BB*. +oo.+|
| .o .O+o. + oo|
| . . ...+=.. o. |
|E . o. ..=.o + o |
| o ...S o . * |
| o..+ . o |
| . oo .|
| . |
| |
+----[SHA256]-----+

A private key located at /c/Users/cambi/.ssh/id_ed25519 is generated as well


as a public key. Two files are generated.

In GitLab select the ADD SSH Key button or go to your profile and select
settings and select SSH Keys from the menu on the left hand side.

Copy your public key to the site. You can access your private and public key
as seen below:

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ cat /c/Users/cambi/.ssh/id_ed25519
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMw
AAAAtzc2gtZW
QyNTUxOQAAACBPUM3uqdXF1HyhRsmq26SX34udMOssN2FpTWNl2PT48wAA
AJikreWSpK3l
kgAAAAtzc2gtZWQyNTUxOQAAACBPUM3uqdXF1HyhRsmq26SX34udMOssN2
FpTWNl2PT48w
AAAEDZywrIP3ldV2G8he17oPOHRRa959wavw9PvPQ12ZgnmE9Qze6p1cXUfK
FGyarbpJff
i50w6yw3YWlNY2XY9PjzAAAAFWNhbWJpQERFU0tUT1AtU0JVVkFRVg==
-----END OPENSSH PRIVATE KEY-----

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ cat /c/Users/cambi/.ssh/id_ed25519.pub
ssh-ed25519
AAAAC3NzaC1lZDI1NTE5AAAAIE9Qze6p1cXUfKFGyarbpJffi50w6yw3YWlNY2X
Y9Pjz cambi@DESKTOP-SBUVAQV

You can also delete this public key here as well. Next we push changes since
we have already committed.

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)


$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream origin master

To have this happen automatically for branches without a tracking


upstream, see 'push.autoSetupRemote' in 'git help config'.

Note: You need to be specific of what you are pushing. Which branches, files
or folders?

cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)

$ git push origin master


The authenticity of host 'gitlab.com (2606:4700:90:0:f22e:fbec:5bed:a9b9)'
can't be established.
ED25519 key fingerprint is
SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added 'gitlab.com' (ED25519) to the list of known
hosts.
Enumerating objects: 47, done.
Counting objects: 100% (47/47), done.
Delta compression using up to 16 threads
Compressing objects: 100% (42/42), done.
Writing objects: 100% (47/47), 4.39 KiB | 1.10 MiB/s, done.
Total 47 (delta 14), reused 0 (delta 0), pack-reused 0 (from 0)
To gitlab.com:kenjo138/test_website.git
* [new branch] master -> master

You might also like