Using_Git
Using_Git
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/
$ git status
fatal: not a git repository (or any of the parent directories): .git
$ git init
$ git status
On branch master
No commits yet
$ git commit
On branch master
Initial commit
$ vim readme.md
Note: Once the document opens, press ‘i’ to insert test and type Hello World!
$ dir -a
. .. .git readme.md
$ 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 status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: readme.md
$ git commit
Note: vim will open with messages referring to commit. Simply press ESC
followed by ‘:x’. You should then see the message above.
$ vim index.html
# Modify the existing file by adding a new line such as ‘I am learning git.”
$ vim readme.md
$ 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
# Can also choose to enter $ git add –all instead of $ git add .
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html
modified: readme.md
$ 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
no changes added to commit (use "git add" and/or "git commit -a")
$ git add .
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: readme.md
$ git status
On branch master
nothing to commit, working tree clean
Using Log Files
$ 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
commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700
My first commit!
commit addf0b15f8e644ef830377d8cb2c2b6ee910ca9a
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:16:22 2024 -0700
Improve readme
commit addf0b15f8e644ef830377d8cb2c2b6ee910ca9a
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 11:16:22 2024 -0700
commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700
My first commit!
$ mkdir temp
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)
$ dir -a
. .. .git index.html readme.md temp
$ git status
On branch master
nothing to commit, working tree clean
$ touch temp\.gitkeep
$ 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)
$ git add .
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: temp.gitkeep
Deleting Files
For untracked files:
$ touch newfile.txt
$ dir -a
. .. .git index.html newfile.txt readme.md temp temp.gitkeep
$ 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)
$ rm newfile.txt
$ git status
On branch master
nothing to commit, working tree clean
$ dir -a
. .. .git index.html readme.md temp temp.gitkeep
$ rm -rf -- temp
$ dir -a
. .. .git index.html readme.md temp.gitkeep
$ git status
On branch master
nothing to commit, working tree clean
$ rm -rf -- temp.gitkeep
$ 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")
$ 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
$ dir -a
. .. .git index.html readme.md
$ git log
commit e8512422632dd98c23475ed22c22bf4acd89d983 (HEAD -> master)
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 09:17:34 2024 -0700
commit 70634b50499a77cceb6c1f25452836484176ba21
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 15:34:41 2024 -0700
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
commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700
My first commit!
(END)
$ mkdir config
$ touch config/private.txt
$ 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.
$ 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)
$ dir -a
. .. .git .gitignore config index.html readme.md
$ git status
On branch master
nothing to commit, working tree clean
Creating Branches
Main and Master Branch are the same branches
$ 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)
$ dir -a
. .. .git config index.html readme.md
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (feature/new-table)
$ vim index.html
$ git add .
warning: in the working copy of 'index.html', LF will be replaced by CRLF the
next time Git touches it
$ cat index.html
<html>
<body>
<h1>My website</h1>
<table></table>
</body>
</html>
$ cat index.html
<html>
<body>
<h1>My website</h1>
</body>
</html>
Note: will protect from mistakenly deleting the branch. To delete the branch
regardless, run the following:
$ git log
commit 779c471c95b4b7ed85045e08d9c69d615cf2e959 (HEAD -> master)
Merge: 39ce803 e5ab069
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 15:54:39 2024 -0700
Added table
commit 39ce803ff1495ecd784e6fdbb1c686442cee4cfa
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 09:51:02 2024 -0700
commit e8512422632dd98c23475ed22c22bf4acd89d983
Author: Louis Rey <[email protected]>
Date: Wed Sep 25 09:17:34 2024 -0700
commit 70634b50499a77cceb6c1f25452836484176ba21
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 15:34:41 2024 -0700
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
commit a2cb6e3b65eaa70d78f6198b05721d8a60311df2
Author: Louis Rey <[email protected]>
Date: Tue Sep 24 09:59:10 2024 -0700
My first commit!
# Now that the merge was completed, the branch can now be deleted.
Recursive Merging
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (master)
$ vim index.html
$ git add .
$ git status
On branch bugfix/table
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
$ vim readme.md
$ git add .
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.
$ 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'
$ vim index.html
$ git add .
$ 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
$ git log
cambi@DESKTOP-SBUVAQV MINGW64 ~/test-website (bugfix/table-2)
$ vim index.html
$ git add .
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")
Note: The merge --abort command will end this conflict. It restores the
master to its original content.
$ git status
On branch master
nothing to commit, working tree clean
$ 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")
Note: This time we will try to resolve the conflict from the merge branch
$ 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.
$ 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")
$ vim 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
$ git status
On branch master
nothing to commit, working tree clean
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
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
$ git remote -v
origin [email protected]:kenjo138/test_website.git (fetch)
origin [email protected]:kenjo138/test_website.git (push)
$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/cambi/.ssh/id_ed25519):
$ 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):
$ 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]-----+
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:
$ cat /c/Users/cambi/.ssh/id_ed25519
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMw
AAAAtzc2gtZW
QyNTUxOQAAACBPUM3uqdXF1HyhRsmq26SX34udMOssN2FpTWNl2PT48wAA
AJikreWSpK3l
kgAAAAtzc2gtZWQyNTUxOQAAACBPUM3uqdXF1HyhRsmq26SX34udMOssN2
FpTWNl2PT48w
AAAEDZywrIP3ldV2G8he17oPOHRRa959wavw9PvPQ12ZgnmE9Qze6p1cXUfK
FGyarbpJff
i50w6yw3YWlNY2XY9PjzAAAAFWNhbWJpQERFU0tUT1AtU0JVVkFRVg==
-----END OPENSSH PRIVATE KEY-----
$ 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.
Note: You need to be specific of what you are pushing. Which branches, files
or folders?