Help me please with usage of git. I'm studying Data Structures and Algorithms and my…
- User
Help me please with usage of git. I'm studying Data Structures and Algorithms and my first day's job was to implement some simple functions with arrays. Now I want to make a repository for my code results. Help me please! This is my pyhon file (by the way, you can comment it also): def getElement(array, index): return array[index]
def printArray(array): for num in arr: print(num)
def sum(array): total = 0 for num in arr: total += num return total
def runningSum(array): for i in range(1, len(array)): array[i] += array[i-1] return array
arr = [1, 2, 3, 4, 5]
print(getElement(arr, 1)) printArray(arr) print(sum(arr)) print(runningSum(arr))
- Assistant
- User
Help me with step 7, please. My step 6 likes like: D:\dsa>git commit -m "Initial commit: add array functions implementation" Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com" git config --global user.name "Your Name"
to set your account's default identity. Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Home@DESKTOP-9HAI0FC.(none)')
D:\dsa>
- Assistant
This error message means Git doesn’t know who you are yet. You need to configure your user name and email in Git before you can make commits. These are used for tracking the author of the commits.
Fix the "Author identity unknown" issue
Run these commands in your terminal (replace with your info):
bashgit config --global user.name "Your Name" git config --global user.email "youremail@example.com"For example:
bashgit config --global user.name "John Doe" git config --global user.email "john.doe@example.com" - User
Now I have this: D:\dsa>git commit -m "Initial commit: add array functions implementation" [master (root-commit) 0f4f48b] Initial commit: add array functions implementation 1 file changed, 29 insertions(+) create mode 100644 array_functions.py
Am I right, this means that it has no connections with github site? Only my laptop knows abou the python file?
- Assistant
Exactly! Your message:
code[master (root-commit) 0f4f48b] Initial commit: add array functions implementation 1 file changed, 29 insertions(+) create mode 100644 array_functions.pymeans:
- You successfully made your first commit to your local Git repository.
- Git is tracking your file and its changes on your computer.
- There's no connection yet between your local repository and GitHub (or any remote).
To connect your local repo to a GitHub repository and push your code online, you need to:
-
Create a repository on GitHub
- Go to https://github.com, log in.
- User
I added two new functions to my file. What I have to do with git? My file (also, it will be cool if you comment it):
Returns the element from the array at the specified index
def getElement(array, index): return array[index]
Prints each element of the array
def printArray(array): for num in array: print(num)
Returns the sum of all elements in the array
def sumArray(array): total = 0 for num in array: total += num return total
Returns running sum array, where each element is the sum of all previous elements including itself
def runningSum(array): for i in range(1, len(array)): array[i] += array[i-1] return array
Return index of the first founded element, if target is not in the array -> return -1
def find_first(array, target): for i in range(len(array)): if array[i] == target: return i return -1
def find_last(array, target): for i in range(len(array)-1, -1, -1):
if array[i] == target: return i return -1Sample array to test
arr = [1, 2, 3, 4, 5]
print(getElement(arr, 1)) # Prints: 2 printArray(arr) # Prints each number in arr print(sumArray(arr)) # Prints: 15 print(runningSum(arr)) # Prints: [1, 3, 6, 10, 15] print(find_last([4, 2, 4, 5], 4)) # Prints: 0 print(find_last([4, 2, 4, 5], 4)) # Prints: 2
- Assistant
- User
Now I want to upload code files from another folder. It is my WEB learning results (html, js and etc.). The structure is WEB (with no files) and sub-folders (Test1 and Project_Name). Test1 is for learning and Project_Name for any projects. Something like that: -WEB --Test1 ---example.js ---example.html --Project_One ---project_one.html ---project_one.css ---project_one.js --Project_Two ---project_two.html ---project_two.css ---project_two.js
For now it looks like: -WEB --Test1 ---index.html ---script.js --ToDoList ---index.html
How to connect it with git and github? I will be really glad with your help!
- Assistant