dev-resources.site
for different kinds of informations.
Your First Commit: A Beginner’s Journey with Git and GitHub
Introduction
Git and GitHub are two crucial tools for contemporary software development that are explained in this article for both novice and seasoned engineers. Git is a distributed version control system that monitors codebase changes, facilitating effective code history management and collaboration. By making repositories available online, GitHub, a web-based platform that leverages Git for version control and provides services like issue tracking, project management, and code hosting, streamlines collaboration.
Setting Up Git
1.Install Git:
- Windows: Download and install Git from git-scm.com.
-
macOS: Use Homebrew:
brew install git
-
Linux: Use your package manager:
sudo apt-get install git
- sign in on git account if you don't have an account
2.Configure Git: (using window OS)
Set your username and email to identify your commits:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
3.Verify Installation:
Check the installed Git version:
git --version
Creating a Repository
Local Repository
1.Navigate to your project folder:
cd /path/to/your/project
2.Initialize a Git repository:
git init
3.Add files to the repository:
git add .
4.Commit the changes:
git commit -m "Initial commit"
Remote Repository
1.Create a repository on GitHub:
- Log in to your GitHub account.
- Click the "+" icon and select "New repository."
- Name your repository and click "Create repository."
2.Link your local repository to GitHub:
git remote add origin https://github.com/yourusername/your-repository.git
- Create
nano readme.md
- Save nano file
-
cat readme.md
andgit add readme.md
- Sign in with your browser
- Authorize git-ecosystem 3.Push your local repository to GitHub:
git push -u origin main
Making Commits
1.Stage Changes: Add modified files to the staging area:
git add <file-name>
Or stage all changes:
git add .
2.Commit Changes: Save changes to the repository:
git commit -m "Your commit message"
Pushing Changes to GitHub
Send your commits to the remote repository:
git push origin main
Pulling Changes from GitHub
Fetch and merge changes from the remote repository:
git pull origin main
Best Practices
- Write clear and descriptive commit messages.
- Regularly pull changes to stay updated.
- Use branches for features and bug fixes.
- Push frequently to avoid losing work.
Featured ones: