forked from puneetbhatia77/intellipaat-15dec-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-notes.txt
122 lines (99 loc) · 3.36 KB
/
git-notes.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
New file (firstfile) working area - (untracked file for git)
add file to local git repo staging area - (added to local git repo)
commit file to local git repo local git area
push to remote repo remote git repo (global/public git repo) --- need internet connection
-----------------------------------------
1. Create a new git file say "firstfile"
2. create an empty git repo using "git init" command. (one time command to create .git folder)
3. git status
4. git add "firstfile" #add to staging area
5. git status
6. git commit -m "initial check-in" #pushed to local git repo
7. git status
--------------------------------------------
git log # to check your commit hostory
git branch # to check current branch (by default master)
vi firstfile
# make some changes
:wq!
git status # modified file
git add . # change is added to staging area
git commit -m "second check-in"
git status
git log
git show # comare the last 2 versions
--------------------------------------
# configure github account and push repo
git remote add origin https://github.com/puneetbhatia77/git-demo-27june.git
git remote -v
git push origin master
-------------------------
git branch test # to create test branch
git branch
git checkout test # switch to test branch
git add .
git commit -m "test branch file"
git push origin master
-----------------------
#merge branches
git checkout master
git merge test
git push origin master
-----------------------
Other Git commands
git branch
echo "This is testfile at master branch" > testfile
git add testfile
git commit -m "initial checkin for test file"
git push origin master
git checkout -b mybranch
git branch
echo "This is testfile in mybranch" > testfile
git add testfile
git commit -m "initial checkin for test file in mybranch"
git push origin mybranch
git checkout - # switch back to master
git merge --help
git merge mybranch
git status
git push origin master
git branch
# Now update testfile manually at github - "initial checkin for test file by other user"
vi testfile -> "initial checkin for test file by other user"
git add testfile
git commit -m "initial checkin for test file by me"
git push origin master - "It will ask first to pull repo for latest changes"
git pull - mege conflict that needs to be resolved manually
vi testfile - resolve merge conflicts
git status
git add testfile
git commit -m "initial checkin for test file by us"
git push origin master
# verify at github
vi .git/config
git commit --amend --reset-author
git config --global user.name Puneet
or
git config --global user.name "Puneet"
git config --global user.mail "[email protected]"
or change .git/config
[user]
name = "Puneet Kumar Bhatia"
mail = "[email protected]"
ssh-keygen
cat ~/.ssh/id_rsa.pub
# and add id_rsa.pub contents to github -> settings -> ssh keys
ssh -T [email protected]
cd ../
rm -rf demo/
git clone [email protected]:puneetbhatia77/demo.git
cd demo/
------------------------
cat .git/config -> change git url - git@git....
or git remote remove origin -> git remote add origin git@git......
-------------------
vi testfile2
git add testfile2
git commit -m "initial checkin for test file 2"
git push origin master
# it will not ask for credentials now.