Shubhankar Valimbe
Posted on September 25, 2023
Hello beautiful people!
Today I'm going to act as a chaperone on your journey to become a GitHub pro. If you're an experienced dev, you already know what it is. For the ones that don't, GitHub is a widely used platform for collaborating on code. This guide will walk you through the process of cloning a GitHub repository, making changes, and pushing those changes to both the main branch and a new branch.
Before starting, please create an account on GitHub if you don't already have one and install Git.
Cloning a GitHub Repository
To get started, you'll need to clone an existing GitHub repository to your local machine. Follow these steps:
Navigate to directory
Open your terminal or command prompt.
Navigate to the directory where you want to store the cloned repository:
cd /path/to/your/desired/directory
Copy Repo URL
Click on the Code button in the upper right corner of repo files and copy the HTTPS URL.
Clone the repo
Clone the repository using its HTTPS URL. Replace username and repository-name with the actual URL of the GitHub repository:
git clone https://github.com/username/repository-name.git
Authenticate GitHub credentials
Git will prompt you for your GitHub username and password (or personal access token, if two-factor authentication is enabled) to authenticate and clone the repository.
Once the clone is complete, you'll have a local copy of the Git repository in the directory you specified.
Making Changes
With the repository cloned locally, you can now make changes to the code or files. You can edit, add, or delete files as needed.
Pushing Changes to the Main Branch
To commit and push your changes to the main branch, follow these steps:
Stage the changes
Stage the changes you want to commit. To stage all changes, use:
git add .
Commit Changes
Commit the changes with a descriptive message:
git commit -m "Your commit message here"
Push Changes
Push the changes to the main branch on GitHub:
git push origin main
Creating and Pushing to a New Branch
To create and push your changes to a new branch, do the following:
Create a branch
Create a new branch locally and switch to it:
git checkout -b new-branch-name
Make and commit your changes in this new branch as shown above.
Push to new branch
Push the new branch to GitHub and set up tracking:
git push -u origin new-branch-name
With these steps, you've successfully cloned a GitHub repository, made changes, and pushed those changes both to the main branch and a new branch. This workflow allows you to collaborate effectively on GitHub projects.
Let me know your thoughts or questions in the comments!
Posted on September 25, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.