Prerequisites
- A free GitHub account - sign up on GitHub
- The email address associated with your GitHub account
- Your newly crafted webpage from the previous exercise
01Install and configure Git
xcode-select --install
git config --global user.name "Your Name"
git config --global user.email "[email protected]"02Generate SSH key for GitHub
To interact with GitHub, you need an SSH key for authentication.
- In the terminal, enter:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- Press
Enterto accept the default file location for your keys.
- Enter a passphrase for extra security or leave it blank.
- Go to the
.sshdirectory:cd ~/.ssh
- Display the SSH key:
cat id_rsa.pub
- Copy the entire output - that's your public SSH key.
03Add SSH key to GitHub
- Go to GitHub in your web browser.
- Click your profile photo, then click on
Settings.
- In the sidebar, click on
SSH and GPG keys.
- Click
New SSH key.
- Paste your key into the "Key" field.
- Click
Add SSH key.
04Create a new repository on GitHub
- Open your web browser and go to your GitHub account.
- In the upper-right corner, click the
+icon and selectNew repository.
- Name your repository, provide a short description, select 'Public' or 'Private', and then click
Create repository.
05Connect your local repository to GitHub
- Go back to the terminal and navigate to your webpage project directory.
- Initialize a local Git repository by typing
git init.
- To connect your local repository to the new GitHub repository, type:
$ git remote add origin https://github.com/username/repository.gitReplace username with your GitHub username and repository with the name you gave your repository on GitHub.
06Push your webpage to GitHub
- Add all the files in your directory to the staging area with git add .
- Commit the changes with a message using git commit -m "Initial commit".
- Push your commits to the GitHub repository with git push -u origin master.
07Basic Git commands
git status: Check the status of changes.
git add .: Add all changes in the current directory to the staging area.
git commit -m "your message": Commit changes to the local repository.
git push origin master: Push changes to the remote repository. Replace "master" with the name of your branch if it's not "master".
08Pull changes
If others have made changes to the remote repository, pull those changes to your local copy with:
git pull origin masterRemember to replace "master" with the name of your branch if it's not "master".
09Create and switch branches
- To create a new branch:
git branch branchname
- To switch to a branch:
git checkout branchname
- To create a new branch and switch to it in one command:
git checkout -b branchname
10Merge branches
Once you're done with your changes on a branch, you can merge it back to the master branch.
- First, switch to the master branch:
git checkout master
- Then, merge your branch:
git merge branchname
That's a basic guide to using Git and GitHub on macOS. Remember, Git is a powerful tool with many more commands and features. It's recommended to look into a more in-depth guide or tutorial as you become more comfortable with these basics.