-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-gitHub_commands.txt
167 lines (135 loc) · 6.38 KB
/
git-gitHub_commands.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
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
Installing Git
sudo apt-get update
sudo apt-get install Git
Verifying the installation
git --version
Configuring the username and email ID
git config --global user.name "Username"
git config --global user.email "Email"
Ignoring Credentails asking again and again for https:
git config --global credential.helper ‘store’
git config --global credential.helper ‘cache --timeout=3600’
SSH setting GIT and Remote Machine
1) Go to terminal window
2) Run the command cd ~/.ssh
3) Now you are inside the .ssh directory of your system.
4) Run the next command - ssh-keygen -t rsa -C “email-id”
5) The above command will generate two ssh keys – Public and Private
6) Go to your system home directory and look for .ssh directory and there you will find one .pub extension file.
7) Open the file and you will see the public key.
8) Copy the public key as it is.
9) Open the GitHub setting page >> go to ssh keys tab >> click on new ssh key
10) Add the key and save it.
11) Now your local machine identity is verified by your GitHub account successfully.
12) Verify the connection by running the command ssh -T git@github.com.
13) You should receive a response as:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Innitialize repo
git init
Move the file from untracked/unstaged to staged area
single file= git add <file name>
multiple files= git add .
Commit
New file= git commit -m "message"
modified file= git commit -am "message"
Connect Local repo with Remote repo
git remote add origin <repo url>
Verify GitHub
git remote -v
Log commands
Commit list in details= git log
Commit list in one line= git log --oneline
List of all the authors within the project (s=summary and n = numbered) = git shortlog -s -n
Commits list by author= git log --author <Author Name>
OR = git log --author=<2/3 starting letters>
Logs of specific file= git log --author <Author Name> <filename>
Logs for a specific file= git log -p <fileName>
Decorated view of log= git log --all --decorate --oneline --graph
OR= git log --graph --oneline
Log view of specific commit= git show <comitid> --stat
View last few commits= git log -<no of commits you want to view>
View logs between specific dates= git log --after <date> --before <date>
Detailed view of logs in one line= git log --stat --oneline
Renameing a file from git
git mv <old name> <new name>
View the list of configuration
git config --global --list
Alias:
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global --unset "alias.name"
git config --global --unset-all
Diff commands:
Difference between two commits= git diff <old commit> <new commit>
Modified VS Commited = git diff <filename>
Staged VS Commited = git diff --staged <Filename>
Staged VS Specific Commit = git diff <commit ID>
Remote VS Local = git diff origin/master master
Pushing Changes to remote Repo
1st time push= git push -u origin <remote branch>
multiple times push= git push
Cloning a repo
Complete repo= git clone <URL of the repo>
Only a branch from the repo= git clone -b <Branch name><Repository URL>
View List of Files
List all files – git ls-files
List stagged files – git ls-files --stage
List of file in a directory – git ls-files --directory <dir name>
Configure git ignore to your system
git config --global core.excludesFile <PATH TO .GITGNORE FILE>
Checkout Commands:
To switch to a branch = git checkout <branchname>
To switch to a remote branch = git checkout <remotebranch>
To switch to a commit git checkout commitid
To switch to a tag git checkout tagname
Clean Command
To view the implication of the clean command - Git clean –dry-run
To force delete the file from the repo - Git clean -f
To delete dir - Git clean -f -d
To delete all the files and dir - Git clean -f -d
To delete all the ignored file in one go - Git clean -f -x
To delete all the files and dir incliding ignored files - Git clean -f -d -x
RM Command
Removes the file from the git and the file system - git rm -f <filename>
Removes the file only from git repo but actual file will still be there in the project – git rm --cached <filename>
Reset Command
Move the file to Staging area= git reset --soft <commit-id>
Move the file to unstaged area= git reset --mixed <commit-id>
Move the files out of records or reverts the file to the stage of previous commited stage git reset --hard <commit-id>
Revert Command
git revert <commitID>
Note:- when you want to revert from 5th commit to 3rd commit then pass the commit id of 4th Commit to revert to the 3rd commit stage.
Amend Command
git commit --amend -m “message”
Tag Command
Annotated tag= git tag -a <tagname> <commit-id> -m "Message here"
Lightweight tag= git tag <tag name> <commit-id>
Get the list of tags= git tag --list
Get the list of tags with their messages= git tag -n
Delete a tag= git tag -d <tagname>
View a specific tag= git show <tagname>
Pushing tags to remote repo= git push --tags
Delete tag from remote= git push --delete origin <tagname>
Stashing Commands
To stash all the files – git stash
To show the list of files stashed – git stash list
To show the latest stash or files stashed at 0th position – git stash show
To show the stashed records at position 1 – git stash show {1} or use git stash show <stash@{0}>.
To stash with a message – Git stash save “message”
To get the files back to work – Git stash pop
To get back the stashed files at position 1 – Git stash pop {1}
This will remove the files from the position 1 and it will also delete the change completely and u cannot undo this – Git stash drop {1} / {stash-id}
Remove all the stashed files in one go – Git stash clear
Stash Show more details= git stash show -p
Stashing a single file= git stash -- <filename>
Git Branching
1) I want to see the branches available in this repository then: Git branch
2) I want to see all the branches including local and remote branches: Git branch -a
3) I want to see all the branches and their last/latest commits along with their message: Git branch -v
4) Delete a branch: Git branch <branchname> -d
5) Rename a branch: Git branch -m <oldName> <newName>
6) If you are on the branch you want to rename: git branch -m new-name
7) to check the parent of a branch = git log -g <branch name>
Change the default branch
git push --set-upstream origin <branchname>