Cloning repository
The easiest one. Nothing can go wrong with this.
1. Go to any repository, press the "Code" (The blue button).
2. Select either HTTPS or SSH.
NOTE: Make sure you have configured your SSH key before cloning it via SSH.
3. Go to any folder directory you wish using Command Prompt or Powershell or Git Bash.
cd "your folder"
git clone "copied link / copied ssh"
NOTE: It will automatically create a folder for you.
git clone "copied link / copied ssh" .
NOTE: If you created a folder for the repository, add a dot behind.
Forking repository
Basically duplicating a repository from others.
1. Go to any repository, press the "Fork" (Top right corner).
2. Leave everything as default. You may change the repository name as the forked repository will be at your disposal.
NOTE: You can't fork your own repository in the same account.
Creating repository
New project in the house.
1. Go to your repository tab, press the "New" (Yes, the blue button).
2. Name your repository and provide a description for it.
3. Choose the repository visibility: Public OR Private.
4. Choose MIT License as default if you want your repository as open-sourced.
NOTE: License is like a copyright to your code.
5. Press the "Create repository" (Yes, blue button again) and your repository is created.
Checking status
Have a sense of security, ehe.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. To know what file created, added, modified, deleted, and which branches you are currently in.
git status
Reverting changes
Thinking of undoing everything, just snap your fingers. I mean stash your repository.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Clearing any created, added, modified, deleted files you made.
git stash
NOTE: It will revert back to the latest pull from main branch you have previously made.
Uploading changes
Saving your edited codes to GitHub, cloud storage but cooler.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Include all files changed.
git add --all
3. Write a commit message as a backlog.
git commit -m "your message"
4. Upload all files to GitHub.
git push origin main/master/"your branch name"
(Optional) 5. If you push from a branch, create a merge request so whoever in charge can have a code review before merging it to the main branch. There will be a link available in your terminal, just "Ctrl + Left Click" and it will redirect you to GitHub. Press on the "Create Pull Request" (YES, blue button! Again).
Downloading changes
Make your repository up-to-date to the latest version.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Update your local file directory.
git pull origin main
NOTE: Always download from the main/master branch.
Fetching branches
Similar to Pull, but it won't make changes to your local files. Recommended for developers to review other developers code before merging.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Fetch new branches.
git fetch
3. Change to the newly fetch branches for code review remotely.
git branch
NOTE: This is to check the branches fetched and its name.
git checkout "the branch"
(Optional) 4. If any changes are made in the fetched branch, update the changes back to the branch in GitHub.
git add --all
git commit -m "your message"
git push origin "the branch"
NOTE: This will update the branch for merging to the main/master branch later.
Create a new branch
Don't touch the main branch if you want to keep your job.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Create a new branch along with the name.
git checkout -b "new branch name"
NOTE: Remember to avoid creating branches with same name. There are ... consequences ... world-ending consequences.
Changing to another branch
Go back to where your codes belong.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Check your existing branches in local device.
git branch
NOTE: The branches available in your local devices may differ to branches in GitHub
3. Go the existing branch.
git checkout "branch name"
NOTE: -b is not needed because you are not creating a new branch.
Checking branches
See what branches you have in your local device.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Check your existing branches in local device.
git branch
NOTE: The branches available in your local devices may differ to branches in GitHub
Deleting branches
Clearing old branches so you won't run out of branch naming ideas.
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Checkout to the main branch.
git checkout main/master
NOTE: Always delete branches from your main branch.
3. Check your existing branches in local device.
git branch
NOTE: The branches available in your local devices may differ to branches in GitHub
4. Delete the branches in your local device. It won't affect the branches in GitHub.
git branch -D "branch name"
Updating existing branches
Using back the same branch again and again is all right, but ...
1. Open Command Prompt or Powershell or Git Bash and go to your repository folder path.
cd "your folder"
2. Update your whole folder by pulling the main branch from GitHub to your local device.
git pull origin main
3. Checkout to your existing branch, if you forgot, then check the branches you have.
git branch
git checkout "the branch"
4. Update the branch you are in by pulling the main branch again.
git pull origin main
NOTE: This time it won't show any stuffs like created, added, modified, deleted, instead it will just show you something something FETCH_HEAD blah blah blah...
Merging branches to main branch
Time to get your hands dirty with conflicts arising. ONLY FOR WHOEVER IN CHARGE.
1. Go to your GitHub and click into your repository.
2. Press "Pull Requests" and you will see all pull requests.
If there is no pull requests, you can create it manually.
(Optional) 3. To create a new pull request, press "New Pull Request" (Blue button). Base branch will be your main branch and compare branch will be the branch you want to merge into your main branch.
4. If there is any conflicts, click "Resolve conflicts". It will show your code and the codes overlapping it, you will need some time to check and clear it.
NOTE: Don't make your seniors' life harder when you are working.
5. If there is no conflicts or resolved, click "Merge Request" and your main branch will be updated with new codes.
(Optional) 6. You can delete the branch if you wish to. A button to delete the branch will appear after you merged sucessfully.
Creating SSH key
Extra protection, less frustration. What the heck were you thinking?
1. Before proceeding, you can check your existing SSH keys if they exist.
ls -al ~/.ssh
NOTE: There are mostly .pub file.
2. Open Git Bash, not other terminal.
3. Generate a SSH key by replacing it with your GitHub email.
ssh-keygen -t ed25519 -C "your GitHub email"
If the above ed25519 algorithm can't be used, use the rsa algorithm.
ssh-keygen -t rsa -b 4096 -C "your GitHub email"
4. It will prompt you:
Enter a file in which to save the key:
Retype the file path provided and replace the SSH keyname with whichever you like.
id_"random keyname"
5. Set your password once and confirm it again.
NOTE: You can't see the password but it is written adn recorded.
6. Start ssh-agent manually.
eval "$(ssh-agent -s)"
It will return your agent pid. It may differ from devices.
Agent pid 59566
7. Add your SSH private key to the agent and replace the id with what you inputted in Step 4.
ssh-add ~/.ssh/id_"random keyname"
8. Copy the SSH public key to your clipboard.
clip < ./.ssh/id"random keyname".pub
9. Open your GitHub and go to "Profile" -> "Setting".
10. Click "SSH and GPG keys" -> "New SSH key" / "Add SSH key".
11. Set any title, leave the key type as "Authentication Key", paste in the SSH public key.
NOTE: Remove any whitespaces or empty rows.
NOTE: Your public SSH key should begin with the algorithmn name and ends with your email address.
12. Press "Add SSH key" and your first SSH key is created.
(Optional) 13. Test your SSH key connection.
ssh -T git@github.com