How put locally edited file to github?

·

2 min read

Steps:

To add a locally edited file to GitHub, there are a few steps you'll need to follow:

  1. Make sure you have a GitHub repository set up for the project. If not, create a new repository on GitHub.

  2. Initialize a Git repository for the project locally if it's not already. You can do this using:

git init
  1. Add the GitHub repository as a remote for your local repository:
git remote add origin git@github.com:[username]/[repository].git
// if you set already then change it like:
git remote set-url origin git@github.com:[username]/[repository].git
  1. Add the edited file to the staging area:
git add [file]
or 
git add . // for all
  1. Commit the changes with a descriptive message:
git commit -m "Edited [file]"
  1. Push the commits to the GitHub repository:
git push origin main

Or if you're using a different branch:

git push origin [branch]

This will push your local changes to the remote GitHub repository.

After your first commit

We push code multiple time in project. so next follow these commands

git status // check which file is modified
git add . or [file] // add file to staged area
git commit -m "file added" 
git push origin main

You can also use GitHub CLI to simplify this process. With GitHub CLI installed, you can simply run:

gh repo create --source=. --push

This will initialize a new GitHub repository, add the local repository as a remote, and push your changes.

happy coding!