Github
This is a web-based platform that helps users store, manage, and collaborate on software projects.
Importance of GitHub:
Collaboration:
Multiple people can work on the same project without overwriting each otherβs work and with full visibility. Team members can view real-time updates, contribute changes, and communicate through the repository file. For private repositories, collaborators must be explicitly added by the repository owner.
Code Storage & Backup:
GitHub acts as a cloud-based repository where your code is safely stored and accessible from anywhere. This minimizes the risk of losing one's code.Portfolio & Career Growth:
Projects that are worked on GitHub can serve as a portfolio to showcase one's skills to potential employers.Open-source code contributions:
GitHub contains numerous codes that are freely available and can easily be modified, integrated, and incorporated into other codes.Version control:
GitHub allows one to track and manage changes made to code.
Creating a GitHub account
- Visit the official GitHub site
- Click on Sign In >> Continue with Google
- Choose your email and username
- Click on create account >> Adjust your profile details and save
Git (Git Bash)
Git is a version-control system, whilst Git Bash is a commanding system that helps a user to communicate lines of code from their local machine and their web-based GitHub account.
Git Bash installation:
- Head to the Git official website
- Install the application; ensure you install an app that is compatible with your operating system.
Connecting Git Bash to GitHub
A successful connection is determined by a couple of steps undertaken in the sequence shown below:
Configuration
git config --global user.name "Your Name" - This command is meant to help set up your username
git config --global user.email "your.email@example.com"- This command is meant to help set up your email address
git config --list - This command is meant to verify your configuration
Generating SSH Key
Run this command to check for existing keys
ls -al ~/.ssh
If you see files named id_ed25519 and id_ed25519.pub (or id_rsa and id_rsa.pub), you have an existing key pair. If not, you'll need to generate oneGenerate the SSH key by running this command:
ssh-keygen -t ed25519 -C "your_email@example.com"
In this step, one will be prompted to save the key. It is paramount that they save it in a file location that one can easily remember and retrieve from
Starting SSH agent
To start the SSH agent, run this command:
eval $(ssh-agent -s)
This command varies based on the user's operating systemAdd your private key to the running ssh-agent
ssh-add ~/.ssh/id_ed25519
Adding the key to Git account
- Copy your public key to the clipboard
- Open the GitHub platform online
- Click on Profile >> Settings
- Click on SSH and GPG keys
- Add new SSH key >> paste the copied key on the clipboard
- Test the connection
Collaboration and version control
To start coding, you will need to create a new repository; this repository will contain the main code. If you need to test changes, create a branch. This allows you to make edits without affecting the main code.
To create a branch on Git Bash if you're using an existing repository:
Git clone **paste the SSH key of the repo** - fetches the open source code from GitHub to Git Bash
cd **repository name** - activates the repo on Git Bash
git branch - shows the main branches available within a repository
git checkout -b **name of the branch** β creates the branch and redirects you to the branch created
git pull - syncs the existing changes
git push origin **name of the branch** - uploads the added branch to the repo on GitHub.
Once you make changes to the Git code, you can proceed to merge the changes using the steps below:
git branch - shows the main branches available within a repository
- The branch highlighted in green is the branch that you are currently working on.
- To move to the branch you want to work on, you can proceed to use the checkout code or the change directory code
git pull - this helps sync the changes made by other collaborators
- It is a good practice to ensure that the file is up to date before making other changes
git merge **name of the file that has the changes**- this will merge the files
- Once you run this command, you get the actions that have been undertaken on the branch
git commit -m "**name of the branch** merged" - this helps confirm the merge
git push - this helps upload the changes to the main repo file
To track the changes that have been made to a code on GitHub, you need to monitor as indicated below:
- Green highlights means that the code has been changed/modified with add-on codes
- Red highlights indicate that the code has been deleted.
- Commits shows the number of changes pushed to the original code
Additionally, you can go back to the original edit on Git if the merged changes were not approved/are wrong. Best practice when using a public repository is to use the revert code. However, when one is using a private repository, you can proceed to delete and forcefully reset the number of commits; this way, the edit that was pushed to the code can no longer be seen
Common terminologies
- Pushing code - uploading changes from one's local machine to GitHub
- Pulling code - downloading changes from GitHub to a local machine
- Command lines - giving instructions to the system through codes
- Version control - tracking and managing changes to code on GitHub
-
Repository (Repo)- cloud-based storage location for project files and code
-
Public repositories are accessible to everyone on GitHub
Use these commands to copy an existing repository from the internet
Git clone paste the SSH key of the repo
cd repository nameto activate the repo on Git Bash
git branchto see the branch available Private repositories are only accessible to the user
-
Common command lines:
git --version - This helps check the Git Bash version
mkdir "Name of the folder" - Creating a folder within GitHub on GitBash
git status - status of on your repository
cd "Created Folder - This is used to change the directory to the folder that was created. All commands that follow this command are within the specifically mentioned folder
touch "Name of file"- This helps create a file within a folder. You should specify the type of file you want to create i.e .py READ.Me
git init - This initializes a new repository which holds the files containing the codes
git branch -a - This lists all the branches within the repository created
Quick Reference Guides & Sources
Git Bash tutorial
Git basics
Git & GitHub visual tutorial for beginners
Top comments (0)