2.9 KiB
2.9 KiB
The Odin Project
How to ask good programming questions
- Be very specific and patient
- use screenshots when available
- ask questions directly instead of asking to ask ie. "are there any java experts around?"
Git
Set up Git
- Set username and email
git config --global user.name "username"
git config --global user.email "email"
- If using GitHub, change branch from 'master' to 'main'
git config --global init.defaultBranch main
- Enable colorful output with git
git config --global color.ui auto
- Set default branch reconciliation behavior to merging
git config --global pull.rebase false
- Verify the config
git config --get user.name
git config --get user.email
Create an SSH Key for repos
- SSH keys are good for avoiding retyping credentials every time
- Check to see if there is an existing ssh key
ls ~/.ssh/id_ed25519.pub
- if nothing appears, then there is no key and one needs to be made
- Create ssh key
ssh-keygen -t ed25519 -C <youremail>
- press enter when asked for what location to store it unless you have a specific location
- add a passphrase and retype it
Link SSH key to Git
- Find the ssh key input on GitHub or repository website of your choice
- Click on new ssh key and give it a name and leave the window open for the next steps
- Copy the public SSH key
cat ~/.ssh/id_ed25519.pub
- Paste the key into your settings, it should start with
ssh-ed25519and end with your email
Change git repository remote
git remote set-url origin https://'username':'password'@repositorylink
Using Git
- Check git version by using
git --version - After creating a new repository you can clone it to your current directory by using
git clone <repolink> - After the cloning, check the url with
git remote -v - Use
git statusto check the status of the current files within your directory - To commit to the repo you can use
git commit -m "Add helloworld.txt" - Confirm with
git status - You can use
git logto view the most recent commits - After creating a file you can use
git add <filename>to add that specific file orgit add .to add all files within the directory that are not on the repo - We can push the changes to the cloud repository with
git push origin main, origin being the remote location and main being the branch to upload to- Make sure to only push working code
Git Best Practices
- Atomic commits
- A commit that includes changes related to only one feature or task of your program.
- Easily reversible if the commit causes breaking changes
- Enables you to write more specific commit messages
- A commit that includes changes related to only one feature or task of your program.
Changing the Git Commit Message Editor
- Typing
git config --global core.editor "code --wait"into the terminal will give you the option to use eithergit commit -m <your message here>orgit commitwithout anything extra.