Logo

dev-resources.site

for different kinds of informations.

Survival Manual: How to Create and Manage a Project in Git

Published at
1/15/2025
Categories
webdev
github
beginners
tutorial
Author
dminatto
Categories
4 categories in total
webdev
open
github
open
beginners
open
tutorial
open
Author
8 person written this
dminatto
open
Survival Manual: How to Create and Manage a Project in Git

Git is an essential tool for developers who want to efficiently manage version control for their projects. In this post, we'll explore how to start a project in Git and perform basic operations such as adding a remote repository, making commits, and synchronizing changes. Let's get started!

github

Initializing a Git Repository

To create a new project in Git, the first step is to initialize a repository. This can be done with the following command:

$ git init
Enter fullscreen mode Exit fullscreen mode

This command creates an empty Git repository in the current directory. For example, when you run git init in the directory c:/Users/Fulano/Posts/, you will see the following message:

Initialized empty Git repository in c:/Users/Fulano/Posts/.git/
Enter fullscreen mode Exit fullscreen mode

Adding a Remote Repository

After initializing the repository, you may want to connect it to a remote repository on GitHub or another Git hosting service. To do this, use the git remote add origin command followed by the URL of the remote repository:

$ git remote add origin [email protected]:fulano/30days.git
Enter fullscreen mode Exit fullscreen mode

If you need to change the remote repository, you can add another one:

$ git remote add origin [email protected]:fulano/the30day.git
Enter fullscreen mode Exit fullscreen mode

Checking the Repository Status

To see what is staged for addition or what has been modified, use the command:

$ git status
Enter fullscreen mode Exit fullscreen mode

This command shows the current state of the repository, including modified and untracked files.

Making Commits

After adding or modifying files, you may want to save these changes to the repository. To do this, use the git commit command with a descriptive message:

$ git commit -m "Here I add a message, like: committing the first post"
Enter fullscreen mode Exit fullscreen mode

Pushing Changes to the Remote Repository

To push your changes to the remote repository, use the git push command. The -u flag sets the default branch for the push:

$ git push -u origin master
Enter fullscreen mode Exit fullscreen mode

If you need to force the push (for example, after rewriting history), use:

$ git push -f origin master
Enter fullscreen mode Exit fullscreen mode

Synchronizing with the Remote Repository

To bring updates from the remote repository to your local repository, you can use git fetch or git pull.

  • git fetch: Downloads the headers (HEADs) and updates local references without merging with the local branch. It's useful to see what has changed in the remote repository:
$ git fetch [email protected]:fulano/books.git
Enter fullscreen mode Exit fullscreen mode
  • git pull: Incorporates changes from the remote repository into the local branch. It is equivalent to git fetch followed by git merge FETCH_HEAD:
$ git pull [email protected]:fulano/30days-30sites.git
Enter fullscreen mode Exit fullscreen mode
  • git pull --rebase: Updates the local repository by rewriting history to maintain a linear history:
$ git pull --rebase [email protected]:fulano/30days-30sites.git
Enter fullscreen mode Exit fullscreen mode

Conclusion

These are the basic commands to start working with Git. Over time, you will become familiar with more features and be able to manage your projects even more efficiently.

These commands are some of the most basic and important ones you'll use when working with Git. I always keep a file with these commands handy in case I forget any of them.

Remember to always keep your repository updated and make frequent commits to ensure your work is safe and well-documented

If you have any other essential Git commands that I might have missed, feel free to share them in the comments! Your input could be helpful to others in the community :)

github Article's
30 articles in total
Favicon
CΓ³mo gestionar tus proyectos de software con Github
Favicon
How to upload Markdown files to Dev.to from GitHub
Favicon
Implantando um aplicativo Angular com DigitalOcean e GitHub de forma gratuita
Favicon
Survival Manual: How to Create and Manage a Project in Git
Favicon
Top 50 Websites a Backend Developer Must Know πŸ–₯οΈπŸ”§πŸš€
Favicon
Unlocking the Power of GitHub Copilot: Your AI Pair Programmer
Favicon
Top 10 Trending GitHub Repositories, Nov 24 2024
Favicon
Improving Port Management Speed: Why I Created `port-client` to Replace `npx kill-port`
Favicon
Unlock Your Coding Potential with the GitHub Copilot Global Bootcamp!
Favicon
Publish Private Nuget Packages on Github
Favicon
Git Merge VS Git Rebase: Which One Should YOU Use?
Favicon
Static sites FTW
Favicon
Hood Ball β€” Multiplayer web-based game
Favicon
GitHub Makeover: Create a Profile README That Stands Out and Connects! πŸ‘¨β€πŸ’»
Favicon
Deploying a Next.js UI App on S3 Using Jenkins🀩
Favicon
The Global South OSC
Favicon
🎁 20 Open Source Projects You Shouldn't Miss in 2025
Favicon
A Conversation with Docker CTO Justin Cormack and Flux CEO Ron Efrani: The Future of Developer Environments
Favicon
Sample Programs Repo Celebrates 1,000 Code Snippets
Favicon
Learn Machine Learning with these amazing GitHub repositories! πŸš€
Favicon
πŸˆβ€β¬› Git and GitHub: A Beginner’s Guide to Version Control πŸš€
Favicon
Undo Mistakes in Git: Revert, Reset, and Checkout Simplified
Favicon
My First npm Package!
Favicon
Top 14 GitHub Data Risks: Data Loss Scenarios and How to Prevent Them
Favicon
Mastering Git and GitHub: A Guide for New Team Members
Favicon
Why I Stopped Using Plain Git Pull (And Why You Should Too)
Favicon
Why I Built commit-ai: A Story About Git Security and Team Safety
Favicon
πŸ”„ Automating GitHub PR Notifications with Slack Integration: A Journey
Favicon
How to Link git to GitHub via SSH on Windows
Favicon
Mastering Git Workflows: Beyond Basic Commands

Featured ones: