forked from vishalverma9572/gittutuorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Git-commands.txt
152 lines (93 loc) · 4.04 KB
/
Git-commands.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
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
git config --global name "vishal" -> set author names
git config --global email "vishal"
git status
git init -> initiate .git folder which tracks
git add --a -> staging of all
git add . -> add all the files in staging
git add text.txt -> add text.txt in staging only
git commit -m "" -> commit with message
touch .gitignore -> creates newfile or folder like here it is creating a new file".gitignore"
touch new.txt
touch logfolder/
cd .. -> change directory to above folder
ls -> list directories inside this directory
cd logfolder/
.gitignore
xyz.txt ->ignores xyz.txt
*.log ignores ever .log file
logfolder/ ingores every logfolder
/logfolder/ ignores only current directory log folder
git diff -> will compare working directory with staging area
git diff --staged -> compares courrent staged area with previous commit
git commit -a -m "this direct commit all tracked file not the untracked file"
Ctrl+c to stop cloning etc
git rm third.txt ->this will delete third.txt as well as staged it now you just commit
git mv first.txt second.txt -> it will rename first to second
Jab ham tracked file ko gitignore me dalenge to bhi git usko track karta rahega
so we have to tell ki ab is file ko track mat karo
->
git rm --cached first.txt
q dabake exit
git log -p ->se ye hame sare commit me diff dikhayega
git log -p -3 ->me bas 3 commit me diff dikhayega
git log --stat -> will show us diff in short
git log --pretty=oneline -> will show us all commits with message
git log --pretty=short -> will show us all commit with message and commitor and author
Author is who jinhone banaya repository
Commitor wo jinhone commit kiya
git log --since=2.days -> it will show commits in last two days
git log --pretty:format:"%h --%an"
git commit --amend -> add to last commit and you can change msg and commit the current changes also
There will apen a vim editor press i to edit
Sabse Niche insert likha ayega now you can edit
After edit to save press esc button and press colun(shift+semin colun)
Write
:wq and press enter
git restore --staged filename ->to unstage the file
git checkout -- first.txt -> undo all the changes till last commit for that file it can't affect.gitignore
git checkout -f -> go back to last commit undoing all the changes including
git remote means ek wesite ya repository
git remote add origin https:/
git remote -v -> shows whhere to push where to pull
git push -u origin master ->will push the changes to the remote
Alias means command ko chhote me likhna
git config --global alias.st status
Now git st eill work as git status
git config --global alias.ci commit
Now git cu will work as git commit
git config --global alias.unstage 'restore --staged-- '
to set git unstage this.txt
git checkout -b newbrnch -> create new branch snd go to that branch
Now you are in newbrnch
Now if you want to go to master
git checkout master
If you delete anything in branch that is ignored in master that will not restore if you will switch to master
git branch -> will show how name branches are there
before switching you should always commit the sit
git merge newbrnch
deal merge conflict
git branch -v -> it will show
Commit hash commit message
git branch --merged
show already merged branches
git branch --no-merged -> show not merged branches
Deleting branches
git branch -d develope
->gives error if develope is not mergerd
git branch -D develope
->Not gives error if not merged
Branching workflow
Log running branches
Master
Develop
PU
Topic branches
If you have any issues you create and solve it
Merge it and delete it
git push -> generaly only push master branch if you want to explicitly push any other branch
Go to that branch
git push origin branchname
if you want to rename at the time push
git push origin oldname:newname
git push -d origin branchname it will delete the branch at remote
git pull The git pull command is used to fetch the latest changes from a remote repository and integrate them into your current branch. Essentially, it combines two Git commands: git fetch and git merge (or git rebase, depending on your Git configuration).