-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-commands
More file actions
181 lines (134 loc) · 6.7 KB
/
git-commands
File metadata and controls
181 lines (134 loc) · 6.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Github_Tutorials
General Concept :
* Working area --> Staging area --> Respository
* Push --> Act of sending file to github from local PC
* Pull --> Act of receiveing from github to local PC
* Remote --> Duplicate instance of repository on remote server
* Clone --> Act of downloading the repository to local PC
Follow the steps:-
Step:-1
Create github Account:
Open github.com
Create account
Create repository (Let it be github_tutorials)
Step:-2
Download and install git:
For windows from : git-scm.com
Install Location on: C:\Program Files\Git
Open git from terminal
Command to check git version : git version
Step:-3
Git configuration username and email:
git config --global user.name "raju-shrestha"
git config --global user.email "rajushrestha2007@gmail.com"
Check the username and email verification:
git config --global --list
OR
git config user.name
git config user.email
Check the Current directory : pwd
Change directory : cd directoryname
change the directory to 1 step back: cd ..
Step:-4
Create directory on PC (Let it be on Desktop) location:
Command to create directory : mkdir directoryname (Directoryname be Github)
Change directory : cd directoryname
Step:-5
Copy/download the repository from github to your local PC called git clone
git clone https://github.com/raju-shrestha/github-tutorials.git
Command to listout the content of current Directory: ls
Go to local repository: cd github_tutorials
Listout the content of local repository: ls
To know the status (change) of current working directory on github : git status
To clear the git command: clear
Connect gitbash to github Remote Repository:
git remote add origin https://github.com/raju-shrestha/github_tutorials.git
Step:-6
Git Add and Commit
Before adding any file you need to initialize git : git init
For add command: git add filename (You can use dot(.) instead of filename to add all files)
For commit command: git commit -m "Commit Message"
Step:-7
Publishing changes back to github (Push):
Before push, first connect to github remote repository:
Command: git remote add origin https://github.com/raju-shrestha/github_tutorials.git
Git push command: git push -u origin master ---> origin is the nickname of github project
Force push command : git push -f origin master
-------------------------------------------------------------------------------------------------------------------
* You can download and install github desktop from here: https://desktop.github.com/
* You need to signin github account from installed github desktop before push
* To push file to remote first you need to clone: git clone https://github.com/raju-shrestha/github-tutorials.git
* Then git add filename
* git commit -m "commit message"
* And, then finally use git push
-----------------------------------------------------------------------------------------------------------------------
# Switch to multiple accout: git config --global credential.useHttpPath True
-----------------------------------------------------------------------------------------------------------------------
Push to an existing Repository from command line:
Push file from local to remote repository:
git init
git add README.md
git commit -m "commit message"
git remote add origin https://github.com/raju-shrestha/github_tutorials.git
git push -u origin master
OR, you can directly use this command:
git remote add origin https://github.com/raju-shrestha/github_tutorials.git
git push -u origin master
--------------------------------------------------------------------------------------
Git Branch:
Branch is the copy of main repository, it is required to work with open source repositiory,
Usually a branch is created to on new features that a main repository do not have.
-->git branch, git merge and git checkout are generally used command .
Some Commands:
List all the branch in the current repository: git branch
Create New Branch:
git branch branchname
Merge Newly Created Branch with Master Branch
git branch merge branchname
Delete Branch:
git branch -d branchname
Switching Between the Branch: This also create the new branch
git checkout branchname
Copy and Download Remote Repository to Local PC:
git clone https://github.com/raju-shrestha/github_tutorials.git <-- Copy and paste SSH Key
See file on locally clone repository: ls
git pull origin master
git add filename --> Add file to master branch
git commit -m "Commit Message"
git push origin master
ROLL BACK YOUR COMMIT:
git reset commitid (you can see commit id using git log command)
------------------------------------------------------------------------------------------------------------------------------
CREATE GIT TAG (VERSIONS):
To create tag: git tag tagname
To see tag: git tag
To push to tag: git push origin tagname
To delete tag: git tag -d tagname
To checkout tag: git checkout tagname , and then to switch to branch : git checkout branchname
References: https://www.drupixels.com/blog/git-tags-guide-create-delete-push-tags-remote-and-much-more
Some Other Useful Commands:
git status --> check the status of current working directory
clear --> To clear git command from terminal
git log --> See the comments history in chronological order ----> q to exit from git log
git rm filename --> Remove file
git mv originalfilename renamed-filename --> To rename original file to other file
git reset HEAD filename --> Bring back to working area(Unstaging area)
git checkout commit-number filename --> Get the previous committed file
REMOVE FILES FROM GIT REPOSITORY
git clean -fd --> removes all file from current directory
NOTE:
To add files on remote repository:
Establish the connection to github remote repository using: git remote add origin https://github.com/raju-shrestha/github_tutorials.git
Initialize git
Add files
Commit message
Push
To add files to local (PC) repository:
clone the repository to create a local working copy of existing remote repository
Pull the changed files to a local repository
Add New files/ Change something to already stored file
Commit files with some message
Push files
ADD FILE FROM COMMAND
touch filename.extension
-------------------------------------****************************************------------------------------------