-
Notifications
You must be signed in to change notification settings - Fork 0
/
GIT.txt
91 lines (70 loc) · 4.65 KB
/
GIT.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
###########
### TOC ###
###########
#> BASICS, GITHUB
#> GITIGNORE
#> BRANCHES
#> WORKFLOW EXAMPLE
###### BASICS, GITHUB
- INIT, STATUS, ADD, COMMIT, LOG
sudo apt-get install git => Installation (linux)
git config --global user.name "Rapid1898" => Config name for the repository (onetime setting)
git config --global user.email "[email protected]" => Config mail for the repository (onetime setting - use the mail using for github.com)
git init => Create repository in the actual directory
git add file.xyz => Add file to the repository / staging area (prepared for later commit)
git add *.html => Add all html-files to the repo / staging area
git add . => Add everything to the repository / staging area from the directory
git add * => 2nd way to add everything to the repository / staging area from the directory
git add README.md => Add readme-file
git rm --cached index.html => remove specific file from the repository / staging area (before commiting!)
git status => Actual status in the git-directoy (eg. added files, changed files, not added,...)
git commit -m "comment" => Commit files which are added / changed in the repo (with comment) - taking a "snapshot"
git log => Show overview about the last activities
git clone github-link => Clone a repository in the actual path
git remote add origin https://github.com/link/Test.git => Link the acutal folder/repo to the github-repo
git push -u origin master => Push with upstream definition (shorthand - to the master)
git push --set -upstream origin answer => Push with upstream definition (longhand - to the branch "answer")
git reset => undo add command before (all files get set back to the initial state)
git reset HEAD~ => undo the last commit
git stash => ignore changes eg. for xlsx on the local machine
=> Pull (update) files from GitHub<br>
(-u saves the paths - so at the next push - it must be only typed push)
""
git pull -u origin master
""
=> Enable pushing with ssh-key in Idea and VSCode
""
Enable open ssh agent: https://dev.to/aka_anoop/how-to-enable-openssh-agent-to-access-your-github-repositories-on-windows-powershell-1ab8
Run commands: https://stackoverflow.com/questions/56490194/vs-code-bitbucket-ssh-permission-denied-publickey
""
###### GITIGNORE
- create a file ".gitignore" in the root-folder of the respository<br>
- this files / folders will be ignored when comitting (and so for pushing to the remote repository)<br>
- github has for eg. some problems with files > 100MB<br>
add folder: /prg/dist/* => all files in this folder will be ignored
add file: /prg.xlsx => this specific file will be ignored
###### BRANCHES
- BRANCH, CHECKOUT, DIFF, MERGE)
git branch newFeature => Create a new branch with the name "newFeature"
git checkout newFeature => Change to branch "newFeature" (from the master-branch)
git checkout master => Return to the master-branch
git branch -d newFeature => Delete branch
git branch -m main => Change name of the branch - eg. for renaming branch "master" to "main"
git checkout -b new => Create a new branch named "new"
git diff head => Show the difference in the files
git diff --staged => Show only the differences for the files which are not commited yet
git merge newFeature => Merge the branch with the master
###### WORKFLOW EXAMPLE
click fork-button in github => fork the initial repository on github (select personal account as target)
click code-button to grab link => get the forked repository clone
git clone github-link => clone the repository to the local folder
git branch answer => create branch "answer"
git checkout answer => set current branch to "answer"
git status => see which branch is curently active (eg. main or answer)
git add . => add all files to the stage (all in the current folder)
(git reset) => when something wrong were added (undo the whole add command)
git status => shows the actual files on the stage
git commit -m "Completed" => commit files from stage ("take snapshot")
git push --set-upstream origin answer => push with upstream definition (to the branch "answer")
select branch on git hub with button => change from main to the branch "answer"
click pull request button => make an pull request to the original repository