-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.txt
111 lines (95 loc) · 5.12 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
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
git
all the data that git uses locally is stored in a folder called .git
most elite programmers don't use github (just use git on local computer)
less terminal command line tool
what to type
create .gitignore file with filepaths to files that are never added/committed
git init {new repo wiht a master branch}
git add filePath/fileName {from workplace to index}
git add . {add everything from workplace to index}
git status {tells you what is untracked (not in index), what is not staged for commit (workplace and index are diff), merge conflicts, and what is staged for commit}
git diff {shows what is different bw workplace and index}
git log {tells you every commit that has happened the current (head) branch (can show github pushes)}
git commit {move index to local repo ("i" to insert, then type title, ":wq" to write and then quit)}
git commit -m "title" {avoid vim}
git restore --staged fileName {restores last index before the last add}
git rm --cached fileName {deletes it from index}
- NEVER USE -f
git branch branchName {creates a branch (in addition to the default master branch)}
git checkout branchName {switches to diff branch}
- can only do if all changes are committed
git branch -d branchName {deletes a branch if all changes are reflected in current branch}
git branch -D branchName {deletes a branch irrespective of merge status}
git merge branchName {merge current branch with branchName}
- merge conflicts are resolved manually (signaled by <<< >>>)
- readd and recommit to resolve merge conflicts
git merge --abort {abort the merge}
git remote add remoteName link {connect local repo to remote repo (remoteName is a var name for the URL)}
git push remoteName branchName {push all local commits of that branch to the desired remote repo}
git pull remoteName branchName {fetch branchName from server and store as a temp branch in local repo, then try to merge with current branch in workplace (confirms that the workplace is up to date with local repo to not lose work) (may be merge conflicts)}
- will ask to commit merge if workplace has changes from whatever is being pulled (":q!" to cancel)
intialize new git repo - git init
branches
- by default on master branch
- new branches for different issues
- creates a copy of root node (can be master or other branch)
- jira (issue tracker)
- makes new branches for different issues
- hooks let this change ur repo
git status
untracked files - git hasn't encountered before
- git add file.extension
- git add folder
- git add folder/*.txt
- git add . (for every file/folder)
changes to be committed - git knows of this file, but it's not committed to local staging area
to tag files that you want to ignore, create a file called .gitignore
- some files that you don't want to commit to github
- logs, credentials, useless shit
- list paths to files to ignore (can also use regex)
- *.txt (works even in subfolders)
http://interactionprototyping.github.io/exercises/images/github/git-stages.svg
3 lvls for local computer
- workspace (just the computer)
- index (medium area between workspace and local repo where you can store before committing)
- git add (workspace --> index)
- "changes not staged" = file in index is diff than workspace
- git diff tells me what exactly is diff
- local repository (stored in .git folder)
- commits are for "milestones" in the project
- git commit (entire index --> local repo)
- will have to use vim
- "i" to insert, then type title
- ":wq" to write and then quit
- hit enter
- git commit -m "title" (to avoid that shit)
git log (shows all commits to local repo)
deleting off of index
- git restore --staged file (reverts it back to the previous add)
- git rm --cached file (deletes it from index)
- NEVER USE -f
branches
- git branch branchName
- "upstream branch" = parent branch
- head is a pointer to which branch you're currently on
- to switch branches, use "git checkout branchName"
- cannot switch if there is any "changes not staged for commit" or "changes to be committed" bc then you'll lose that version
- git branch -d branchName
- will only delete if everything in branchName is reflected in current branch
- git branch -D branchName
- deletes irrespective of merge status
merging
- git merge branchName (this is going to make current branch updated to the branchName)
- if the current one is ahead of the other one, there may be merge conflicts
- merge conflict will display some >>>> <<<< stuff in file, choose one version manually then commit
- merge conflicts happen bc >1 isn't committed or there is similar content and algo cannot determine which to choose
- either add desired version to index OR abort merge (git merge --abort)
- can only merge with upstream branches
git servers (github is one)
- local repo can be connected to multiple remote repos (git remote add origin https://github.com/bbqiu/testing.git)
- origin is the name of the server (can be anything, basically defining URL to be this name)
- git push remoteName branchName (push master branch onto origin remote)
- git push pushes all local commits to the server
- git pull origin master
- first fetch from server with temp branch in local repo
- then try to merge with current branch in workspace