-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit.txt
More file actions
199 lines (134 loc) · 8.16 KB
/
git.txt
File metadata and controls
199 lines (134 loc) · 8.16 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
* We can run Linux commands using git bash, that's the reason we use it.
* Gitbash is a command line shell
* Git is a version control system for tracking changes in computer file. It's userd for coordinating work among several people on a project and tracking progress over time.
* Git is a software that can be installed directly onto our systems. It's used Source Code Management in software development.
* Version Control System = It's a system that records all the changes made to a file or set of files, so a specific version may called later if needed. This helps in collaboration with all team members.
* It allows multiple users to work together.
* Large projects can be handled efficiently.
* Git can be used offline and doesn't need internet connection for use.
* Git can be used without Github
* Used for version control and code sharing.
* There's no GUI.
* Code changes like commit, merge, etc. are done using commands from the command line.
* Open source licensed.
* Alternatives/Competitors are
- Mercurial, Supervision, IBM, Rational Team Concert and ClearCase
* Github = It's a Git repository hosting service, which provides web-based graphical interface. It's hosted on the cloud.
* Github can't be used offline and needs internet connection for use.
* Used for centralised source code hosting on the cloud.
* It provides an easy to use GUI.
* Everything is done through a web-based interface.
* Includes a free and pay for use tiers.
* Alternatives/Competitors are
- Atlassian, BitBucket and GitLab
* git --version
* git init
* git config --global user.name 'Manoj Kumar'
* git config --global user.email 'manoz@gmail.com'
* git config --list ( will list all the settings )
* git config --list/-l --global ( will list only the global settings )
* git config --list/-l --local ( will list only the local settings )
* git config --list/-l --system ( will list only the system settings )
* git add index.html
* git status
* git stash (OR) git stash -u --> Removes files from staging area
* git stash list
* git stash show
* git rm --cached index.html
* git restore --staged <file | .>" to unstage (OR) git reset --> Used to undone "git add"
* git commit -m 'changed a file'
* git log (OR) git log --oneline (OR) git log --author="manoz" (OR) git log --before="DATE" --> it shows all the commit history
* git diff --> Shows the differences between current repository and changes that were made.
* git diff master 2nd --> Shows the differences between "master" & "2nd" branches.
* "git merge --abort" to abort the merge
* rm -rf .git --> Makes the git folder normal folder - removes .git folder
* git --help
* git help commit -a
* git checkout -- . --> To make current branch files un-modified
* git remote show origin --> Shows if local reposiory is upto date with remote repository or not. And show pullable & pushable branches from local to remote.
We can also use two other commands to check if local reposiory is upto date with remote repository or not.
-> git fetch origin (THEN) -> git status
* To check the differences between local and github before the pull use below commands
-> git fetch origin (THEN) -> git diff master origin/master
* To create a branch
-> git branch branchName(Login)
* To switch to another branch
-> git checkout branchName(Login)
* We have a shortcut to create a new branch and switch into it with below command
-> git checkout -b branchName
* The command to list all branches in local and remote repositories is
-> git branch --all/-a
* If you require only listing the remote branches from Git Bash then use this command
-> git branch -r
* If you require only listing the local branches then use this command
-> git branch -l
* You may also use the show-branch command for seeing the branches and their commits as follows
-> git show-branch
* To delete a branch
-> git branch -d branchName --> This will delete the branch but it shows notification of changes - preffered
-> git branch -D branchName --> This will delete the branch without showing any changes notification
* If we want to merge Login to Master branch
-> git merge login
* With above command, all the changes which were made inside of "Login" branch will be merged inside of "Master" branch
* If we want to go to previous commit after commit a new commit, so first we need to see the logs, in the list of logs al the commits will be shown with HASH code. Then we need to run below command
-> git revert HASH(7af537f)
And again if we want to move ahead, then
-> git revert HEAD (Basically it will take it to the recent/last commit)
* If we want our branch to be upto date with any branch for example master branch after doing a new commit, then
-> git rebase master
* To push local repository to server(GIT), first we need to create a repository in our GITHUB account. Then it will give instructions to add our local repository to server
* git remote add origin {{ URL of our server repository }}
* git remote
* git push -u origin master
* Once we push our local repository to server, then if we make any changes and want to add those changes to server we can simply use below command. But again we no need to repeat above step.
* git push
* git remote rm origin (Removes Origin)
* To push all branches which are exist in local branch & remote branch, use below command
-> git push --all
* To clone a repository use below command
-> git clone {{ URL }}
* To get all the changes from remote repository to our local repository, use below command
-> git pull
-> git pull origin develop
* $ git push
fatal: The current branch 2nd has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin 2nd
*
====================================================================================
To ignore file OR folders:
----------------------------------------------------
First we need create '.gitignore' file using below command
* touch .gitignore
* Then if we want to ignore "log.txt" file, then we need to add that file name with it's extension in '.gitignore' file. Ex: log.txt
* If we want to ignore a directory with a name "dir1", then we need to add that directory name in '.gitignore' file in a new line. Ex: /dir1
* To ignore all text files, use - "*.txt"
====================================================================================
Shortcuts:
------------------------------------------
* git add *.html
* git add .
*
Points:
------------------------------------------------------------------------------------
* If we use 'git commit', it will open VIM editor. We need to press 'i' to insert text there. After entering some text, we need to click "Esc" key then type ":wq" to save the file.
Git messages and their meanings:
------------------------------------------------------------------------------------
* Message: Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
* Message: Your branch and 'origin/2nd' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Meaning: Our local repository has a commit which is not exist in Server repository & Server repository has a commit which is not exist in our local repository.
*
********************************* Useful Links *********************************************
* https://stackoverflow.com/questions/3541647/git-add-vs-git-commit-a
* https://www.youtube.com/watch?v=rgbCcBNZcdQ --> Creating a Simple Github Pull Request
* https://www.youtube.com/watch?v=ytSoabxSQ6E --> Support for password authentication was removed Github Fixed using Token (August 13, 2021) - Linux
*** https://www.youtube.com/watch?v=b5oQZdzA37I --> Git Commands With Examples | Git Tutorial | Git Branching & Merging | DevOps Training | Edureka
* https://www.youtube.com/watch?v=xJXgvr8bPes --> Git vs GitHub | Git And GitHub Difference | What Is Git And GitHub? | Git And GitHub | Simplilearn
* 5 Github Hacks that you should know | for Coders (Includes Keyboard shortcuts)
https://www.youtube.com/watch?v=B67X9xtOyuI
* https://git.io/ --> URL shortner
********************************* Useful Github users *********************************************
* https://github.com/machadop1407