I need a link for a guide to pushing to GitHub

I pushed to my repo last night using git bash. I was able to push a readme file I just created but not the other files that had changes. They are all marked with ‘m’.

How do you push updates to your repo? Here is what I did so far:

git status
git add filename
git commit -m 'message'
git checkout
- that didn't do anything
git push origin master
only added readme file
git commit -m 'new msg'
git push -u origin master
no changes added to commit (use "git add" and/or "git commit -a")
git commit -a 
- that messed up everything

pwd
git status
git push origin master

I got these messages in the terminal:

  1. Your branch is up to date with ‘origin/master’.
  2. no changes added to commit (use “git add” and/or “git commit -a”)

If you know of a GREAT blog post where all this is covered, that would be awesome!

Hi @kernix !

I use git checkout to go to other branches.
So maybe that is not what you wanted to do here.

It only added the readme file because of this line here

If you want to stage all of your files and you are in the current working directory you can use this

git add .

Here is an article on how to add all files

Usually what I do for pushing multiple files is the following.

git status
git add .
git commit -m "some commit message"
git push

This looks like a good article to read.

FCC also has a course

Hope that helps!

2 Likes

Thanks, let me check out those links and try the commands you listed. Will that work for all files changed after the initial commit? I was able to push the files from inside VS code but I didn’t know what I was doing there either. I would like to do it from git bash and from vs code without error each time. I also have a 1 hour+ long video from FCC in my YouTube watch later playlist. Thanks!

Whenever you make new changes you should be able to make new commits and push those to your repo on github.

I always use git status to see where I am at in the process.

Hi,
I found a couple of resources. They may come in handy.

https://www.neonscience.org/resources/learning-hub/tutorials/git-setup-remote

This one is a 3 min video.

Thanks, I’ll check them out!

I tried the commands you provided and here is what I got:

git status
git add .
git commit -m "some commit message"
git push

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Kernix13/WriterAssist.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Then I tried to do it fropm VS Code and the changes were gone but it didn’t push to my repo - let me read those docs and watch the video

Did you make changes directly on the GitHub repository itself and not pull those changes down locally?

If so, then you will need to do git pull to get those changes on your local machine before you can push the new changes.

Here is a stack overflow answer explaining it more.

So in order:

Check which files are staged for commit, and which have been committed:

git status

Stage one file to to committed:

git add filename

Commit anything in staging (so currently that one file) with a message attached:

git commit -m 'message'

Not really relevant here:

git checkout

Following isn’t quite true, if you ran git status again, whatever filename is would have moved from being listed as unstaged to being listed as commited:

- that didn't do anything

Push committed files. You committed one, so that’s what gets pushed:

git push origin master

Now nothing to commit, you haven’t added anything new:

git commit -m 'new msg'

Now nothing to push, you haven’t added or committed anything new:

git push -u origin master
no changes added to commit (use "git add" and/or "git commit -a")

Nothing to commit, you haven’t added anything new:

git commit -a 

Then you’ve done something, possibly reset everything? You now have a repo pushed up to GitHub with that one file, so:

Running this should have given you some information:

git status

Add all the files locally:

git add .

Commit everything that’s been added:

git commit -m "some commit message"

But you already have something on GitHub, and after whatever you did, GitHub is now possibly ahead of where you are now locally. As it is, I assume there’s just that one file, but git doesn’t know that it would actually be safe to override and push up everything even though there seems to be a duplicate. So when you do this:

git push

It fails, you need to pull the changes down from GitHub first, which will ensure you are up to date, then you can push safely

So that is what I noticed in VS Code - you have to do pull them push. Why is that? I didn’t make any changes on github.

This means that you had changes on the remote (GitHub) that you did not have locally (on your computer). Something changed between the two, somehow.

You have commits from two different users. I assume you are both of them?

If so you did change the README, maybe you did it directly from within GitHub which would make the README on the repo different than the one you have locally.

Oh, I may have manually made changes to the README or contributing.md files while in GitHub.

When you create a new repo on GitHub, the default README.md displays instructions on how to get started. After you follow those instructions, the typical Git commands you’ll use most often in sequence are:

git add
git commit -m “message”
git push

Generally you shouldn’t try to make modifications to files directly on GitHub.com. If you do have any changes on GitHub, git pull will “pull” it down to your local copy.

Thanks. I’m still trying to learn these nuances or basics that I’m unfamiliar with. I started watching freeCodeCamp’s crash course on Git so hopefully, that will answer my questions.

Did you come right with Git?
Some Github repositories (all of mine) have main instead of master so push would be:
git push origin main

I just looked at one of mine and it has ‘master’. But I was confused with the process in general: pushing for the first time with U/untracked files and then pushing for M/modified files. I watched a number of videos and took notes on their docs so now I have a good feel for the commands to use based on where I am in the process.

I haven’t done anything with creating branches since I am working alone on my repos. I would like to find a repo where the owner is open to contributors and see if I could learn the commands for branches. I play guitar and have a guitar chord based website so I searched and found some repos that have code to build SVG chords. I’m not sure how to contact the owners, but most of the ones I found haven’t been updated in years. I may have to create a 2nd GitHub account and try to do the branch thing from that account to my repos.

Of ‘main’ vs ‘master’, I’m condensing my notes and I have this as working under pushing new files:

Initial push:
0. git init | 1. git status | 2. git add -A or git add . | 3. git status | 4. git commit -m ‘notes’ | 5. git remote add origin url(from overview page) 6. git branch -M main (main or master)| 7. git push -u origin master |

I got that to work but should my #6 and 7 match with either ‘main’ for both or ‘master’ for both? All I know is that set of commands worked for me.

From videos I watched, it seems Master was the default name for the Main in repositories. I don’t know if it is a new/ old thing or what. But whatever the Main ‘tree trunk’ is for your repository, that is what you use. Branches then Fork off the Main or Master - and Pull Requests (or Pushes from the remote side) merge back into the Main or Master, whichever the case may be.

What kind of person are you? My guess- you are a nice person, since you like coding and play guitar . . .
I play keyboard, violin and guitar too.
I have a private repository. It is a Household Budget I am writing in Python.
I was going to do it all by myself, because it is specific to my requirements ( not for a client / I am my client ), but am considering opening it to certain people who are genuine, responsible, sensible, etc and won’t “mess it up” for a laugh. Are you interested?

FYI, “git status” doesn’t effect any changes (it’s purely informational), whereas the other commands do effect a change. Keeping that in mind, this is a better order of commands:

  1. git init
  2. git remote add origin [git_url]
  3. git add [filename] (you can add a whole folder with “.”, or selectively choose individual files)
  4. git commit -m ‘[commit_message]’
  5. git push

“git branch” is typically only needed when you’re creating a new branch, i.e. “git branch -b [branch_name]”.
“-u” on “git push” isn’t really necessary either, and can have unintended consequences
“master” is now an outmoded name, and you can omit it anyway; Git will assume the main branch

Also on the subject of “master” vs “main”: GitHub to replace "master" with alternative term to avoid slavery references | ZDNet