Akhmed
Akhmed

Reputation: 1219

How can I upload committed changes to my GitHub repository?

I used clone to create a local copy of my repository on GitHub.

I modified a few files. Then I did: git commit -a

And now I want to save my committed changes to the GitHub repository.

How can I do that?

Upvotes: 14

Views: 49634

Answers (6)

SmellyCat
SmellyCat

Reputation: 750

A scenario that's not covered in the question is when branch-protection applies to the original repository. Then, a change to main or master is likely to be rejected when you attempt to push. The original question said "clone of my repository" but you're more likely to clone a repository of which you are not the original owner.

If you have updated a protected branch like main and the subsequent push attempt has been rejected, you need to rename your branch. You can choose a branch name that isn't already used and describes the changes that you made.

Branches can be renamed using git branch -m <branch name>.

Then, you should be able to push successfully using git push.

Upvotes: 0

Hiruna Fernando
Hiruna Fernando

Reputation: 1

If you want to commit your changes of the code/ project into github use the below codes in your terminal.

  1. git checkout main (if your project has "main branch")
  2. git pull
  3. git merge master (to merge the changes with the master branch)
  4. git add .
  5. git commit -m "Commit Message"
  6. git push

Upvotes: 0

urvashi bhagat
urvashi bhagat

Reputation: 1183

Follow this steps:

1. cd /project path
2. git add *
3. git commit -m "Enter commit message here"
4. git push

Upvotes: 12

Ervis Trupja
Ervis Trupja

Reputation: 2810

To publish your local changes follow the 3 simple steps below:

  1. git add <filename> or git add * to add everything
  2. git commit -m "Enter e message here"
  3. git push

Upvotes: 2

Tobi
Tobi

Reputation: 81813

You push your changes:

git push origin master

Replace master with the name of the branch you want to push, if different from master.

In case the branch was updated since your last update, the changes may be rejected. In that case you have to pull the latest changes on the remote branch first:

git pull origin master

Optionally, you can rebase your changes on top of the remote master (this will prevent a merge commit), by using:

git pull origin master --rebase

Upvotes: 21

Richard
Richard

Reputation: 3386

You want to push your changes to the central repo with git push. It might prompt you for your github password.

Upvotes: 3

Related Questions