Git : Install2023/07/25 |
Install and Configure Git which is the Revision Control System.
|
|
[1] | Install Git. |
root@dlp:~# apt -y install git
|
[2] | It's possible to use for any common user. For example, Create a repository with a user on localhost. |
# create an empty repository debian@dlp:~$ mkdir project.git debian@dlp:~$ cd project.git debian@dlp:~/project.git$ git init --bare hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty Git repository in /home/debian/project.git/
debian@dlp:~/project.git$
# create a working directory debian@dlp:~$ mkdir work debian@dlp:~$ cd work debian@dlp:~/work$ git init hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty Git repository in /home/debian/work/.git/ # set username and email address debian@dlp:~/work$ git config --global user.name "Server World" debian@dlp:~/work$ git config --global user.email "serverworld@dlp.srv.world"
# create a test file and apply it to repository debian@dlp:~/work$ echo testfile > testfile1.txt debian@dlp:~/work$ git add testfile1.txt debian@dlp:~/work$ git commit testfile1.txt -m "Initial Commit" [master (root-commit) 5e4fdad] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txtdebian@dlp:~/work$ git push /home/debian/project.git master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 231 bytes | 231.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To /home/debian/project.git * [new branch] master -> masterdebian@dlp:~/work$ git ls-files testfile1.txt # set any name to the repository debian@dlp:~/work$ git remote add origin /home/debian/project.git debian@dlp:~/work$ git remote -v origin /home/debian/project.git (fetch) origin /home/debian/project.git (push)debian@dlp:~/work$ git remote show origin * remote origin Fetch URL: /home/debian/project.git Push URL: /home/debian/project.git HEAD branch: master Remote branch: master new (next fetch will store in remotes/origin) Local ref configured for 'git push': master pushes to master (up to date) # possible to push with the name you set above debian@dlp:~/work$ echo testfile > testfile2.txt debian@dlp:~/work$ git add testfile2.txt debian@dlp:~/work$ git commit testfile2.txt -m "New Commit testfile2.txt" [master f6dfd1e] New Commit testfile2.txt 1 file changed, 1 insertion(+) create mode 100644 testfile2.txtdebian@dlp:~/work$ git push origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 2 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 258 bytes | 258.00 KiB/s, done. Total 2 (delta 0), reused 0 (delta 0), pack-reused 0 To /home/debian/project.git 5e4fdad..f6dfd1e master -> master # for the case to clone existing repository to empty working directory debian@dlp:~/work$ mkdir ~/work2 debian@dlp:~/work$ cd ~/work2 debian@dlp:~/work2$ git clone /home/debian/project.git Cloning into 'project'... done.debian@dlp:~/work2$ total 4 drwxr-xr-x 3 debian debian 4096 Jul 24 19:07 projectdebian@dlp:~/work2$ ll project total 8 -rw-r--r-- 1 debian debian 9 Jul 24 19:07 testfile1.txt -rw-r--r-- 1 debian debian 9 Jul 24 19:07 testfile2.txt |
Sponsored Link |