-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_learn.txt
137 lines (77 loc) · 4.23 KB
/
git_learn.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
GIT works on 3 stages-->
1.) Present working directory --> the directory on computer whuch is git directory and on which the project is worked on
2.) Staging Area --> the area where the where the files are sent which are needed to be pushed on to the repository
3.) Git repository --> The files are commited here using commit command
git init --> to make a directory as git directory and git will start tracking changes in that directory
--> For configuring username and email for git . Used for local configuration
git config user.name "<user-name>"
git config user.email "<user-email>"
--> For global configuration
git config --global user.name "<user-name>"
git config --global user.email "<user-email>"
--> To get the list and username and user email
git config --list
--> tells that new file is added or present files were modified or if the directory is under git or not
git status
--> Takes all the file to the staging area which will be commited further
git add --a
--> Takes a specific file to the staging area
git add <filename>
--> Commiting the files -m is message , before commiting files should be added first
git commit -m "<commit message>"
Example--> git commit -m "First commit"
--> Opens the present working directory in the vs code
code .
--> Clears the terminal
clear
--> shows all the commits made onthe directory
git log
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CLONING A PROJECT
--> cloning git repository
git clone <URL>
--> to show all the files and folders in the directory
ls
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
IGNORING A FILE DURING COMMITING OR ADDING
1.) make a .gitignore file
2.) Enter the filename to be ignored while pushing and to ignore a folder write <folder-name>/ in .gitignore file
3.) To ignore all files of a particular extension write *.<file-extension> in .gitignore file
Example--> to ignore all .txt file add *.txt to .gitignore file.
4.) add and commit the files.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--> To see the diffrence between working directory and staged data
git diff
--> To compare staged data with last commit
git diff --staged
--> directly commiting files without adding or moving files from present working directory to repository
git commit -a -m "<message>"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
UNSTAGING AND UNMODIFYING FILES IN GIT
--> To remove a file form staged position
git restore --staged <file-name>
--> To get the file from staging area
git restore <file-name>
--> to get all the files from staging area
git restore .
--> to get the file from last commit
git checkout <file-name>
--> to get all the files from the last commit
git checkout -f
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--> When a file is renamed after commiting by a diffrent name in git then the git shows that the file was deleted and new file was formed
having the name as the renamed name.
--> After adding the file git recognizes that the file was actually renamed and no files were deleted.
--> using mv command we can rename the file and the dit knows it without staging it
git mv <current-file-name> <file-name-to-replace>
--> To remove a file
git rm <file-name>
--> To stop git from tracking a file which was being tracked previously
git rm --cached <file-name>
After running above code git status shows that the file is deleted.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
WORKING ON REMOTE REPOSITORY
1.) MAKING NEW REPOSITORY by pressing + button on top left and then giving repository name.
2.) -->Connecting a repository to local git
git remote add origion <link>
3.) Generate an SSH key by searching at google to push the code to github