- Published on
Getting Started with Git
2 min read
- Authors
- Name
- Christopher Morales
- @
Table of Contents
- Short Summary
- Process
- Creating/initializing Git Repository
- Configure Push Defaults
- Adding Files to Staging Area
- Include .gitignore in Staging
- Check Staging Status
- Configure User Information
- Configure Credential Helper (Optional)
- Commit Changes
- Add a Remote Repository
- Rename the Default Branch (Optional)
- Push Changes to GitHub
- Enter GitHub Credentials (if asked)
- Conclusion
Short Summary
This article provides a comprehensive, step-by-step guide on initializing a Git repository, configuring essential settings, and connecting to a remote repository on GitHub. Whether you're a beginner or looking for a quick reference, this guide will walk you through the process with clear instructions and explanations.
Process
Creating/initializing Git Repository
This command initializes a new Git repository in the current directory:
git init
Configure Push Defaults
Set the default behavior for 'git push' to be more straightforward:
git config --global push.default simple
Adding Files to Staging Area
Add all files to the staging area. The asterisk (*) represents all files:
git add *
Include .gitignore in Staging
Ensure that your .gitignore file is included in the staging area to specify files and directories to ignore during version control:
git add .gitignore
Check Staging Status
View the status of your changes in the staging area:
git status
Configure User Information
Set your email and username to associate your commits with your GitHub account:
git config --global user.email "youremail@umich.edu"
git config --global user.name "Your X. Name"
Configure Credential Helper (Optional)
Optional but convenient steps to cache your credentials for a specified period:
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=604800'
Commit Changes
Commit the changes with a descriptive message:
git commit -m "first commit"
Add a Remote Repository
Link your local repository to a remote repository on GitHub:
git remote add origin URL_LINK
Rename the Default Branch (Optional)
Optionally, rename the default branch from "master" to "main":
git branch -m master main
Push Changes to GitHub
Push your committed changes to the remote repository on GitHub:
git push -u origin main
Enter GitHub Credentials (if asked)
Enter your GitHub username and password when prompted
Conclusion
Congratulations! You've successfully created a Git repository, configured essential settings, and connected it to a remote repository on GitHub. This step-by-step guide is designed to help you get started with version control, making it easier to collaborate and manage your projects efficiently. Feel free to explore more advanced Git features as you continue your journey into the world of version control.