30
  • I created a new repository on github.
  • I selected one of the options that added a README.md.
  • I then cd into the project on my hard drive.
  • I ran git init: Initialized empty Git repository in /Users/myusername/github/myproject/.git/
  • I ran "git add ." and then "git commit -m 'project files'", which responded with this:

    [master (root-commit) ca52fe0] project files
     981 files changed, 257939 insertions(+), 0 deletions(-)
     create mode 100644 index.php
     create mode 100644 license.txt
     create mode 100644 readme.html
     create mode 100644 wp-activate.php
     ...
    
  • I then ran "git remote add origin https://github.com/myusername/myproject.git"
  • I then ran "git push origin master"
  • I then ran "git status" which said nothing to commit

But I look at repo and my "my project files" commit is not there. So then I ran git pull and got this:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

and then git push and checked again and still my commits are not on github repo. The only time I can see the commit is when I run "git log":

MacBook-myproject myusername$ git log
commit ca52fe090e6dbf1b6aa6ee51c3283efbe7549904
Author: User <myemailaddress>
Date:   Sat Jun 23 19:22:05 2012 -0400
project files

I followed github directions best that I could. What am I doing wrong?

JohnMerlino
  • 3,900
  • 4
  • 57
  • 89
  • When I run the above command, I get this: origin https://github.com/username/gitproject.git (fetch) origin https://github.com/username/gitproject.git (push) – JohnMerlino Jun 24 '12 at 00:23
  • Also, the initial push command should be: `git push -u origin master` The -u flag indicates that your local branch should be a "tracking" branch of your remote branch. – Christopher Peisert Jun 24 '12 at 00:25
  • yes these are not the real urls. username refers to my github username and the projectname is the actual project name – JohnMerlino Jun 24 '12 at 00:32
  • Also I noticed that when I ran git pull, it gave me an error that I added to the question – JohnMerlino Jun 24 '12 at 00:35
  • this is confusing to me. I used to be able to push with `git push` without having to specify the origin (or the branch). But now I can't push without doing `git push -u origin master`. My removes look fine `originn git@github.com:brando90/ultimate-utils.git (push)` after going `git remote -v`...what happened to my git configuration than now I have to explicitly specify where I am pushing and git push by itself is not longer working? – Charlie Parker Sep 02 '21 at 18:03

4 Answers4

27

After your Github repository has been created (i.e. you can view it on Github), then you should already have:

1. Local repository set up:

git init

2. README file created and added to the repository:

touch README.md
git add README.md 
git commit -m 'first commit'

3. A remote called origin linked to your repository:

git remote add origin https://github.com/username/repo.git

4. An initial push, which copied your local README to your Github repository:

git push -u origin master

If you can view your repository on Github, then it has been successfully created. In this case it looks like you may have edited your README file on Github using the online editing tools, which caused your remote and local branches to diverge.

Before you can push your local changes to Github, you need to fetch or pull your remote changes, merge the changes locally (merging is automatic with pull), and then push to the remote.

See Pro Git: Fetching and Pulling from Your Remotes

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • this is confusing to me. I used to be able to push with `git push` without having to specify the origin (or the branch). But now I can't push without doing `git push -u origin master`. My removes look fine `originn git@github.com:brando90/ultimate-utils.git (push)` after going `git remote -v`...what happened to my git configuration than now I have to explicitly specify where I am pushing and git push by itself is not longer working? – Charlie Parker Sep 02 '21 at 18:02
  • @CharlieParker Did you take a look at this question: [Default behavior of "git push" without a branch specified](https://stackoverflow.com/q/948354)? – Christopher Peisert Sep 02 '21 at 22:38
4

When you created the repository on GitHub you selected initializes remotely containing a README.md file. The next step would be to run git clone https://github.com/username/repo.git in your terminal. At this point you have a local copy on the GitHub repository, so you would then move in your project files. Run git add * then git commit -m 'first commit' then git push origin master. Your changes should now be visible on GitHub.

  • this is confusing to me. I used to be able to push with `git push` without having to specify the origin (or the branch). But now I can't push without doing `git push -u origin master`. My removes look fine `originn git@github.com:brando90/ultimate-utils.git (push)` after going `git remote -v`...what happened to my git configuration than now I have to explicitly specify where I am pushing and git push by itself is not longer working? – Charlie Parker Sep 02 '21 at 18:02
3

After a git commit you need to push the changes

git push origin master to push in master branch

git push origin branch_name to push in secondary branch

Complete work flow for a branch:

git checkout -b aosp_in_docker //checkout a branch and switch into it
git branch // to check all branches current branch will have * sign
git status //to check status of file
git add .  //add untraced files
git commit -a -m 'added a docker container'
git push origin aosp_in_docker // push changes
git staus // check if success
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
  • this is confusing to me. I used to be able to push with `git push` without having to specify the origin (or the branch). But now I can't push without doing `git push -u origin master`. My removes look fine `originn git@github.com:brando90/ultimate-utils.git (push)` after going `git remote -v`...what happened to my git configuration than now I have to explicitly specify where I am pushing and git push by itself is not longer working? – Charlie Parker Sep 02 '21 at 18:02
0

I think most times it happens with new users who are not familiar with branches. branches . check the branches if you have more than one. I think you are pushing changes to another branch.

Asad Khan
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 24 '22 at 20:53