-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.txt
More file actions
127 lines (89 loc) · 3.7 KB
/
Copy pathgit.txt
File metadata and controls
127 lines (89 loc) · 3.7 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
#Install git on windows via https://git-scm.com
#To Initialize a git repository within directory
git init
#To view the status of the repo
git status
#To stage/add a file for commiting
git add <filename>
#To commit a file, adding a message
git commit -m "message for committing"
#To download repo from github
git clone <github url>
#Push changes from branch master to origin master
git push origin master
#Save credentials while on Linux
git config --global credential.helper store
#Commands to get locally created git repo to connect to github
#Create repo on github with same name but do not initialize
git remote add origin <github url>
git remote -v
git push origin master
#To set upstream master so you can just run git push
git push --set-upstream orgin master
#To view history of commits
git log
-----------------------------------------------------------------
#To get a list of all branches of a repository, working branch is *'ed
git branch
#To create a new branch
git branch <new branch name>
#To switch to another branch
git checkout <new branch name>
#To create and checkout to brank in one command
git checkout -b <new branch name>
#To set new upstream branch to push to, -u or --set-upstream
git push -u origin <new branch name>
#To delete a branch locally on workstation
git branch -d <branch name>
git branch -D <branch name> #forcefully deletes
#To delete a branch on github, click branches link, then select delete icon
#To merge newer branch into the working branch, checkout to working branch and run
git merge <newer branch name>
#Pull request on Github = pull someone elses changes into your repo, called merge request on Gitlab
#When working with others, good practice is to not commit on master branch, but rather use pull requests from other branches to master
#After you push changes to branch, from your branch repo click Compare & pull request button on github
#After changes to github repo, pull down changes (fetch+merge)
git pull origin master
-----------------------------------------------------------------
#To view tags
git tag -l
#Tag your latest commit with a version number
git tag v1.0
#To push your tag information to github
git push --tags
#You can also create tagged versions on github.com as well as delete them there
-----------------------------------------------------------------
#Adding github collaborators
- On github, go to settings->collaborators and add github users
- Protect master branch by going to settings->branches
- select Protect->Require pull reviews & Include administrators
#Github workflow
- clone->branch->work->add->commit->push->pullrequest->merge->pull
#To get any changes from github
git fetch
#To merge changes fetched from github
git merge origin/master
-----------------------------------------------------------------
#A fork is a github or gitlab thing, way to copy someone's repo at a point in time for yourself
- Click the Fork button on github to put in your repos
#If you want to grab new changes from where you forked
git remote add <original repo github address>
#To view remote master branch name
git remote -v
#To pull changes from remote master branch
git pull <remote branch name>
#Pull you new changes back to github
git push
-----------------------------------------------------------------
#Create a hidden .gitignore file that will describe what to not put on github. Put in main directory
touch .gitignore
#Add to .gitignore a single file to ignore such as passwords.txt
nano .gitignore
passwords.txt
#Add an entire directory to be ignored such as directory secrets/
nano .gitignore
secrets/*
#Ignore any file with the extension .exe
nano .gitignore
*.exe
#Github has .gitignore templates to help at https://github.com/github/gitignore