Command Line GitHub: A Step-by-Step Guide
Uploading to GitHub through the command prompt, or Git Bash, is a powerful and efficient way to manage your Git repository. This guide will walk you through the process, from setting up Git to initializing a new repository and pushing your changes to GitHub.
Let's begin by ensuring Git is installed on your computer. If not, you can download it from the official website: https://git-scm.com/downloads.
Setting Up Git
Once Git is installed, open your command prompt and type the following to confirm the installation:
git --version
Next, configure Git with your name and email using the following commands:
git config --global user.name "Your Name"
git config --global user.email youremail@example.com
Initializing a New Repository
Now, navigate to the local directory containing the project you want to upload to GitHub. Use the following command to initialize a new Git repository:
git init
After running this command, a new .git folder will be created in your project directory, indicating that the repository has been initialized.
Adding and Committing Changes
To start tracking changes in your project, add all files using the following command:
git add .
Now, create a meaningful commit message and commit your changes with:
git commit -m "Your meaningful commit message"
Connecting to GitHub
Create a new repository on the GitHub website: https://github.com/new, and then connect it to your command prompt with:
git remote add origin https://github.com/yourusername/your-repo-name.git
Pushing Changes to GitHub
To upload your local repository to GitHub, use the following command to push the master branch:
git push -u origin master
or, for newer Git versions:
git push -u origin main
You will be prompted to enter your GitHub username and personal access token (PAT) or password.
After a successful push, your project files will be uploaded and available on your GitHub repository page.
Whenever you make changes, add, commit, and then push (using git push origin master or git push origin main) to update your GitHub repository. Keep exploring the Git documentation for more advanced features and commands.
Happy coding, and enjoy the convenience and power of Git and GitHub with the command prompt!