To commit changes to a Git repository, you can follow these steps:
- Make sure you are in the root directory of your Git repository. You can navigate to the root directory using the command line.
- Use the
git status
command to see the changes you’ve made to your files. This will give you a list of the files that have been modified, added or deleted. - Use the
git add
command to stage the changes you want to commit. You can add individual files usinggit add <file>
or you can add all modified files usinggit add .
- Once you’ve staged the changes, use the
git commit
command to commit the changes to your local repository. You can add a commit message with the-m
flag, like this:git commit -m "Commit message here"
. - After committing the changes, you can push the changes to a remote repository, like GitHub or GitLab, using the
git push
command.
Here’s an example of the commands you could use to commit changes to a Git repository:
git status
git add .
git commit -m "Update README.md"
git push origin main
This example assumes that you’re working on the main
branch and that your remote repository is named origin
.