forked from PushkarOM/NewRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitnotes.txt
103 lines (62 loc) · 3.16 KB
/
gitnotes.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
# Set the global Git configuration for user name
git config --global user.name "Your Name"
# Set the global Git configuration for email
git config --global user.email "[email protected]"
# These configurations are used for making contributions and pull requests
# Create a directory (folder)
mkdir -p 'path'
# Change into the created directory
cd 'path'
# Initialize the directory as a Git repository
git init # (Leave it empty or provide a path; if empty, it uses the current directory)
# Add the URL of the Git repository you want to contribute to
git remote add origin "URL"
# Clone the repository from the online Git repository to your local system
git clone "URL"
# Create a text file (other extensions can be used) named 'readme'
echo 'readme' > or >> readme.txt #(> to add content/overwrite >> to add content to existing content)
# Show the status of files in the directory (staged/unstaged/untracked)
git status
# Commit changes with a commit message
git commit -m "Commit message"
# Add files to the staging area (use '.' to add all files)
git add <filename> or .
#to remove files
git rm --cached <path> (to remove and added repository)
# Create a new branch from the main branch
git checkout -b branchname
# Push changes to a specific branch (useful when contributing to another repository)
git push -u origin branchname
# Push changes to the main branch of your own repository
git push origin master/main
# Move one directory back in the path
cd ..
# List folders and files in the current directory
ls
# Show the origin link for fetching or pushing
git remote -v
#better Git Notes:-
git is a command line tool which helps you keep track of changes to code.
Can synchroniz code between different people.
It helps us to creat a branch and test your code without interfearing with your original code.
It allows us to revert back to older version.
git commands:-
git clone <url> #take a repository and download it to our system
git add <filename> or . (for all the files in the directory)
git commit -m "message" #takes a snapshot of all the added files in the downloaded repository (cahnges made till now are only affecting the local code/file.folder)
git status (tells what currenlty is going on in the repository)
git push (take all of the changes and push it to github)
## git commit -am "commits all of the file that are changed"
git pull #takes all the changes that happend in github an copies the latest changes to the system
#merge Conflicts#
If someone on make a commit changing a line on there system and you do the same by changing something on that line on your system, when you pull/push the code it will create a merge conflict. git work by adding and removing line from the code, when 1 single line simultaneouly get changed on 2 place it causes a conflict.
git log (describes each of the commits)
git reset #reset the current state of repository to an older version
## git reset --hard <commithash>
## git reset --hard origin/master
#branching
git branch (name of current branch)
git checkout -b style (create new branch 'style')
git checkout style (switch)
merging changes made in different branches
git merge style (merges style to main/master)