-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_help.txt
113 lines (51 loc) · 4.67 KB
/
git_help.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
<to paste someting in cmd use shift+ins>
git config --h #for help commands
git help config #for detailed explnations (only after init )
git config --global init.default branch`` main # to initialise it
cd <project path here> #Change Directory to the specified path
git init #for creating the repo(gets reinitialised if already created which is fine)
git status #check status of the files
git add <filename.extension> #to add a file to track
git rm --cached <filename.extension> #to untrack it
# create a text file with .gitignore EXTENSION to ignore files in your repo
#simply write the filename along with the extension in that file to ignore it
# use '#' to write a comment in it
# refer the github website to know the different ways in which you can ignore files
#might be useful to ignore some autogenerated files
git add --all #or --a or --. to add all the files to track
git commit -m "<a meesage>" #to commit
git diff #shows what differences you made from the last time you committed
#there are three environments,working files,staging and committed files
#only staged files get commited (by the add) command
git restore --staged <filename.extension> #to restore a staged file back to working file
git commit -a -m "<message>" # bypasses the staging process and directly commits
git rm "filename.extension" #to delete a file rm->remove
git restore "filename.extension" #to restore a file back
git mv "oldfilename.extension" "Newfilename.extension" #to rename a file mv->move
git log #view your commit histories
git log --oneline #a brief commit history
git commit -m "message" --amend #to amend the previous commit message without making a commit""
git log -p # to get a detailed view of your previous commits (press q to exit)
git help log # opens a help webpage to see all the different ways you can check your log
git restore <tag> # to restore to a previous commit
git rebase -i --root #to modify the way previous commits appear (its complicated) (to exit press colon+x+enterkey)
git branch <branchname> #create a new branch
git branch #shows the branches and the asterisk shows which branch im currently in
git switch <branchname> #to switch to a branch
git merge -m "message" <whatbranchyouwantomergebackintomain> #to merge a branch back into main
git branch -d <branchname> #to delete a branch d->delete
git switch -c <branchname> #creates a branch and switches to it
#resovling merge conflicts :if you have created a branch but since then the main branch has changed then it results in a merge conflict
#if there is a merge conflict branch will turn into main-merge branch
#there go to the file whiich is conflicted and you can see head(current changes) and tail(changes in the branch whuch is to be merged) keep what is needed and delete all else.
#commit these changes to the main branch
-----------
adding a remote address(github)
-----------------
git remote add <name> <https address or ssh> #to connect to a remote address
git remote set-url <name> <new https or ssh> #to set a new url or ssh to the existing remote
git push -u <remotename> <branchname> #to push a branch to the hub
git push --all #to push all the files
git fetch #to bring in your local system (but in a different branch)
git merge #merge the fetched
git pull # does both fetching and merging