Git : Install2022/09/27 |
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 ubuntu@dlp:~$ mkdir project.git ubuntu@dlp:~$ cd project.git ubuntu@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/ubuntu/project.git/
ubuntu@dlp:~/project.git$
# create a working directory ubuntu@dlp:~$ mkdir work ubuntu@dlp:~$ cd work ubuntu@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/ubuntu/work/.git/ # set username and email address ubuntu@dlp:~/work$ git config --global user.name "Server World" ubuntu@dlp:~/work$ git config --global user.email "serverworld@dlp.srv.world"
# create a test file and apply it to repository ubuntu@dlp:~/work$ echo testfile > testfile1.txt ubuntu@dlp:~/work$ git add testfile1.txt ubuntu@dlp:~/work$ git commit testfile1.txt -m "Initial Commit" [master (root-commit) ffab540] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txtubuntu@dlp:~/work$ git push /home/ubuntu/project.git master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 232 bytes | 232.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To /home/ubuntu/project.git * [new branch] master -> masterubuntu@dlp:~/work$ git ls-files testfile1.txt # set any name to the repository ubuntu@dlp:~/work$ git remote add origin /home/ubuntu/project.git ubuntu@dlp:~/work$ git remote -v origin /home/ubuntu/project.git (fetch) origin /home/ubuntu/project.git (push)ubuntu@dlp:~/work$ git remote show origin * remote origin Fetch URL: /home/ubuntu/project.git Push URL: /home/ubuntu/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 ubuntu@dlp:~/work$ echo testfile > testfile2.txt ubuntu@dlp:~/work$ git add testfile2.txt ubuntu@dlp:~/work$ git commit testfile2.txt -m "New Commit testfile2.txt" [master 6de7da8] New Commit testfile2.txt 1 file changed, 1 insertion(+) create mode 100644 testfile2.txtubuntu@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), 256 bytes | 256.00 KiB/s, done. Total 2 (delta 0), reused 0 (delta 0), pack-reused 0 To /home/ubuntu/project.git ffab540..6de7da8 master -> master # for the case to clone existing repository to empty working directory ubuntu@dlp:~/work$ mkdir ~/work2 ubuntu@dlp:~/work$ cd ~/work2 ubuntu@dlp:~/work2$ git clone /home/ubuntu/project.git Cloning into 'project'... done.ubuntu@dlp:~/work2$ total 12 drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 ./ drwxr-x--- 7 ubuntu ubuntu 4096 Sep 23 05:22 ../ drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 project/ubuntu@dlp:~/work2$ ll project total 20 drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 ./ drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 ../ drwxrwxr-x 8 ubuntu ubuntu 4096 Sep 23 05:22 .git/ -rw-rw-r-- 1 ubuntu ubuntu 9 Sep 23 05:22 testfile1.txt -rw-rw-r-- 1 ubuntu ubuntu 9 Sep 23 05:22 testfile2.txt |
Sponsored Link |