#DAY 2-Coding Journey
A Beginner's Guide to GitHub Commands
Introduction: GitHub is a popular platform for version control and collaborative software development. Whether you're a developer, a student, or a tech enthusiast, understanding the basic commands of GitHub is essential for managing your code and collaborating with others. In this blog post, we'll explore some fundamental GitHub commands to help you get started.
git init: The first step in using GitHub is to initialize a new Git repository. The command
git initcreates an empty Git repository in your current directory, enabling version control for your project. Once initialized, you can start tracking changes to your files.git clone: To obtain a copy of an existing repository from GitHub, you can use the
git clonecommand. It creates a local copy of the remote repository on your computer. For example,git clonehttps://github.com/username/repositorywill clone the repository to your current directory.git add: Before committing changes, you need to stage the modified files for inclusion in the next commit. The command
git add <file>adds a specific file, whilegit add .stages all the modified files in the current directory. This step prepares your changes for the commit.git commit: Once you have staged your changes, it's time to create a commit. The command
git commit -m "commit message"records your changes and creates a new version of the repository. The commit message should be concise and descriptive, summarizing the changes you made.git push: After committing your changes locally, you can push them to the remote repository on GitHub using
git push. The commandgit push origin <branch>uploads your commits to the remote repository's specified branch. For example,git push origin mainpushes the changes to the 'main' branch.git pull: To update your local repository with the latest changes from the remote repository, you can use
git pull. This command fetches the changes and merges them into your current branch, keeping your local repository up to date. It's good practice to perform agit pullbefore making your own changes to avoid conflicts.git branch: Branching allows you to create separate lines of development within your repository. The
git branchcommand lists all the branches in your repository, whilegit branch <branch_name>creates a new branch with the specified name. You can switch between branches usinggit checkout <branch_name>.git merge: When you want to combine changes from one branch into another, you can use the
git mergecommand. It integrates the changes from the specified branch into the current branch. For example,git merge feature_branchmerges the changes from 'feature_branch' into the current branch.