This guide walks you through the process of initializing a new Git repository, setting up a .gitignore
file, renaming the default branch to main
, and finally pushing your changes to a remote repository.
See also:
git init
.gitignore
:Use your favorite editor to create a .gitignore
file. Add patterns for files and directories you want to ignore.
Example:
echo "node_modules/" >> .gitignore
echo "*.log" >> .gitignore
git add .
main
:git branch -m main
git commit -m "Initial commit"
Replace your_remote_url
with the URL of your remote repository.
git remote add origin your_remote_url
Before rebasing, especially if you’re unsure about the process, consider backing up your files. You can make a zip of your directory or copy it to another location.
Once backed up:
git pull origin main --rebase
Now, you can safely push your changes to the remote main
branch:
git push -u origin main
With these steps, you’ve initialized a new Git repository, added files, renamed your branch, and pushed everything to a remote repository. Remember to always be cautious when working with Git commands, especially rebasing and force pushing, as they can modify commit history.