Git Command 2
Git Command 2
2 ======================
3 [github.com] Create a remote repository in github.com [User should have github
account]
4
5 [local machine] Init local repo
6 [local machine] Link local repo with remote repository
$git config --global user.name 'abc'
$git config --global user.email '[email protected]'
7
8 echo "# second-repo" >> README.md
9 git init
10 git add README.md
11 git commit -m "first commit"
12 git branch -M main
13 git remote add origin https://github.com/github06022021/handson-basic.git
$git config --global credential.helper store [Store password]
14 git push -u origin main
16 Use case: 2
17 ============================
18 Second user activities
19 - Cloning and modfication of a file , then push to repo repo.
20 ============================
21
22 84 mkdir second_user
23 85 cd second_user/
24 87 git clone https://github.com/github06022021/handson-basic.git
25 89 cd handson-basic/
26 91 vi README.md [use any text editor to modify this file]
27 92 cat README.md
28 93 git status
29 94 git add README.md
30 git add . [for all files]
31 95 git commit -m "Feature 2 impl"
32 96 git push -u origin main
34 Use case: 3
35 ============================ ============================
============================
36 First User activities after second user pushed the changes
37 <change directory to local repo>
38 Eg: /home/labsuser/handson-basic [It is a first user git repo in local
machine]
39 ============================ ============================
============================
40 $ cat README.md
41 First configuration
42 Second
44 $ git pull [it downloads all the remote changes to the local system.]
45
46 Output>>
47 remote: Enumerating objects: 5, done.
48 remote: Counting objects: 100% (5/5), done.
49 remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
50 Unpacking objects: 100% (3/3), done.
51 From https://github.com/github06022021/handson-basic
52 9cfa72a..f05c9a3 main -> origin/main
53 Updating 9cfa72a..f05c9a3
54 Fast-forward
55 README.md | 1 +
56 1 file changed, 1 insertion(+)
57
58 $ cat README.md
59 First configuration
60 Second
61 Third
62
63 Use case: 4
64 ===============================
65 Create a feature branch via Github.com [Switch branch/Tags]
75 $ git branch
76 output>>
77 *Feature-1. [current working branch]
78 main
79 $ vi README.md
80 $ git add README.md
81 $ git commit -m "Feature 1 impl "
82 $ git push -u origin <branch name>
86 Use case: 5
87 ===========
88 Merge the Feature branch into anthoer branch/ main branch
89 User should be changed to branch in which merging is required.
90
97 Use case: 6
98 =========
99 To use ".gitignore" [git is looking for this file to ignore the file pattern]
file: to stop tracking of unwanted files eg log, temp, intermidiate build files.
100 $ cat .gitignore
101 *.txt
102 tmp/
103 output
104 classes
105 $ git add .gitignore
106 $ git commit -m "Added gitignore"
107 $ git push
108
109
117 Jira:
119 Bug:
120
121 Reviwers:
122 Set the commit template in git conf. Based on the scope, we can choose the
level. It can be local, global and system.
123
127
150 [Set a configuration for all git users in the system [perticular machine]. Set
the commit template at System level.
151 $sudo git config --system commit.template /home/labsuser/commit-template.txt
152
203 app4
204
209 delete
210