Introduction
Lets say you and I decide to come up with one of the best recipes for pancakes. But instead of the obvious flour, water and oil, we choose to improve that recipe. And this is how we do it,if you make pancakes today, you write it down on a notebook and send a picture of the same to me ,I use the same recipe tomorrow and add my improvements. With time, there will be significant changes. Lets say we get to day 10. And notice the sugar is abit too much and somewhere along the way,one of us,added the amount. We simply go back to either, our notebooks or check the images shared and can notice who made the changes in the recipe.
So basically you have a local notebook and online copy of the same to do the same. In developers terms,the two tools are git and github.
Lets dive right into it. By definition,
GIT
A free, open-source, distributed version control system (VCS) that tracks changes in source code during software development, allowing teams to collaborate, manage different versions, revert to past states, and work offline efficiently with local repositories.
GITHUB
A web-based platform for hosting source code and facilitating collaboration and version control among software developers and other users.
Git is a tool, and GitHub is a service that uses that tool.
CREATING GITHUB ACCOUNT
To create a GitHub account, go to https://github.com/login, enter your email, choose a password and unique username, complete the puzzle verification, then enter the code sent to your email to finish signing up and access your dashboard. You can also use Google or GitHub Enterprise accounts for social sign-up if preferred.
DOWNLOADING GIT
To download Git, visit the official website at git-scm.com and select your operating system. The installation process varies slightly depending on whether you use Windows, macOS, or Linux.
- Download the installer: Go to the official Git for Windows website and the download should start automatically.
- Run the installer: Once downloaded, run the executable file (ending in .exe).
- Follow the prompts: Click "Next" to accept most of the default settings, which are suitable for most users. The installer will install Git and Git Bash.
Simple commands
- Verify: Open Command Prompt or PowerShell and type
git --version
- Set your name:
git config --global user.name "Your Name"
eg
git config --global user.name "Kamanda Bryan"
- Set your email:
git config --global user.email "youremail@example.com"
eg
git config --global user.email "kamandamulwa@gmail.com"
I think we dived way too deep,my bad,let me explain.
What we've done is verification or confirming whether the installation was successfull then setting the user name and email. Allow me to mention this guide for windows users,for linux users kindly visit https://git-scm.com/install/linux and https://sourceforge.net/projects/git-osx-installer/files/git-2.23.0-intel-universal-mavericks.dmg/download?use_mirror=autoselect for MacOs others kindly visit https://github.com/git-guides/install-git for guidance.
Back to Business,now that we've downloaded Git and GitHuB,let link them for ease of communication between the 2.
When you connect to a GitHub repository from Git, you need to authenticate with GitHub using either HTTPS or SSH(Secure Shell Protocol). And for this example,allow me to use SSH key,we are keeping it simple.
Find guide on adding SSH Key https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
Push and pull
To push and pull code using Git, you interact with local and remote repositories via specific commands in your terminal or command prompt. The git push command uploads your local commits to the remote repository, while git pull downloads new commits from the remote and integrates them into your local branch.
How to push code from VS Code to GitHub
1.Using the VS Code GUI
- Open your project in VS Code.
- Open the Source Control panel: Click on the Source Control icon on the sidebar or press Ctrl+Shift+G.
- Stage your changes: Click on the '+' icon next to each changed file to stage files individually, or click on the "Stage All Changes" icon at the top to stage all changes.
- Commit your changes: Enter a commit message in the input box at the top of the Source Control panel. Press Ctrl+Enter to commit the staged files.
- Push your changes: Click on the '...' button at the top of the Source Control panel, then select "Push" from the dropdown menu. If you are pushing to a new branch, select "Push to" and enter the branch name.
2. Using the VS Code terminal
- Open the integrated terminal in VS Code: Use the shortcut Ctrl+` (Control + backtick) or navigate through View -> Terminal.
- Stage your changes: Run the command:
git add .
3.Commit your changes:
Run the command:
git commit -m "Your descriptive commit message"
4.Push your changes:
To push to the main branch, run:
git push origin main
NOTE:To push to another branch, replace main with your branch name.
Steps to Pull Codes
- Open your terminal or command prompt and navigate to your project directory.
- Ensure you are on the correct branch (e.g., main or master) you want to update using the command:
git checkout <branch-name>
- Run the git pull command to fetch and merge the latest changes from the remote repository into your current local branch:
git pull origin <branch-name>
In most cases, if your current branch is tracking a remote branch, you can simply run:
git pull
Top comments (1)
Simple. Thank you.