This respiratory includes my LeetCode practice and provides an instruction for anybody new to GitHub.
To push your Java code to GitHub from a Mac, follow these steps:
-
Navigate to Your Project Directory: cd /path/to/your/project
-
Initialize a Local Git Repository: git init
-
Create a
.gitignoreFile:- Create the
.gitignorefile: touch .gitignore - Open the
.gitignorefile with Nano or any text editor: nano .gitignore - Add the following lines to the
.gitignorefile:.DS_Store: macOS-specific file that stores folder customizations..bin/: Directory containing compiled binary files..classpath: Eclipse-specific file for classpath settings..project: Eclipse-specific file for project metadata..settings/: Directory containing Eclipse-specific settings.
- Save and exit (in Nano: Press
Ctrl + X, thenYto confirm, and pressEnter).
- Create the
-
Add, Commit, Connect, and Push:
- Add files to the staging area: git add .
- Commit the changes: git commit -m "First commit"
- Add the remote repository URL: git remote add origin https://github.com/username/repository.git
- Push the changes to the
mainbranch: git push origin main
-
Later Updates:
- Add modified files to the staging area: git add path/to/your/ModifiedFile.java
- Commit the updates: git commit -m "Update"
- Push the updates to the
mainbranch: git push origin main
-
Fetch the latest changes from the remote and merge them into your local branch:
- git pull origin main
Check out this YouTube video: https://www.youtube.com/watch?app=desktop&v=LPT7v69guVY
Make sure using token rather than password:
- login to your GitHub account
- go to https://github.com/settings/tokens
- click on "Generate new token"
- make necessary selections (but must select repo)
- click on "save"
- System will have a token
- use this token instead of a password in the eclipse or other tools you are using