Pushing my first repo using terminal

Hi,
I am new to github and have been using terminal for a while now. I have my project which is in magento, and i downloaded magento ignore file to add to my directory. Now i want to upload the folder (minus the ignored files), somehow it doesn’t work.
The way i am working now is,

  1. I have .git folder in my magento folder
  2. .gitignore is also in magento folder

steps i did

git add *
git commit -m “first message”
git push origin <address.git>

All i see in my repo is empty. what am i doing wrong?

1 Like

What is the response (on the command line) from the git push origin master command?
Do you have a repository setup in GitHub.
Be careful not to confuse “git” with “GitHub”. They both use ‘git’ but the terms are not interchangeable and will cause terrible confusion when discussing problems with your source control if they are mixed up together.

What is the result of this command?

$ git remote -v
1 Like

You should add your GitHub remote to your git repository.

So if you haven’t done this already, git push origin won’t do anything because it doesn’t know what origin is. Run the following command:
git remote add origin https://github.com/user/repo.git where origin is the name you are giving to your remote, user is your GitHub username and repo is your repository’s name.

Then you should run this:

git push -u origin master

Ps.: Although using a command line interface gives you more flexibility (and I actually encourage learning and using it), if you are more comfortable, it’s better to use a Git GUI, such as https://desktop.github.com/. It does all the job of connecting your git repo to a remote, adding/removing files, commiting, pushing, etc.

1 Like

new_branch https://github.com/user/Gen.git (fetch)
new_branch https://github.com/user/Gen.git (push)
origin https://github.com/user/Gen.git (fetch)
origin https://github.com/user/Gen.git (push)

I don’t understand, what is origin, when you said, “it is name of your remote”, can you give a example?[quote=“Mateus, post:3, topic:210923”]
Although using a command line interface gives you more flexibility (and I actually encourage learning and using it),
[/quote]
I am not using github desktop as i want to get comfortable with terminal git, though i know desktop would be much easier. Still i want to get acquitted by git terminal

origin is the way your remote repository is aliased on your system, and by the result of git remote -v, I can see you have named your remote repository as origin (this is usually what’s used anyway). So when origin is mentioned, it’s referencing to your remote repository - in your case, https://github.com/user/Gen.git.

What do you get when you run the following code from your project directory?
git push -u origin master

error: failed to push some refs to ‘https://github.com/user/Gen.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.

Try running: “git pull” (without the quotes). That is saying that there are conflicts.

[quote=“RyanReese, post:8, topic:210923”]
Try running: “git pull”
[/quote]so i fixed the conflict using
git merge --abort
and after that i ran
git pull
which told me to specify a branch, so i did following
git pull new_branch
and i got this,
you asked to pull from the remote ‘new_branch’, but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

I didn’t understand the origin, should i re run this command every time? I think it throws a error, something like origin already exists?

Try git pull --all to get ALL branches.

There are many details about how git works that you should master before simply trying to sling around commands. Let me recommend, as a start, GIT Fundamentals, followed by, perhaps Code School: Try Git.

1 Like

I agree with @ParkinT in this one. Git is very abstract and it can be very overwhelming to dive in it just like that. This SitePoint book written by Shaumik Daityari is short and concise. I’d give it a try.

In the meantime, why don’t you start your git project from scratch? I’d delete the .git directory from your project folder then, if my remote repository doesn’t have any files, I’d delete it from GitHub (Go to the repository, then Settings → Remove), save my files in a new directory and I’d start it all over again.

Create a brand new repository on GitHub and after, on the command line:

cd new_project_folder
git init
git remote add origin https://github.com/user/repo.git
git add .
git commit -m "Initial commit"
git push -u origin master
1 Like

so i took the apporach onto another folde/project and it worked! yay, but back to this project i don’t know what is wrong, here is what i get
Please make sure you have the correct access rights
and the repository exists.
MacBook:magento user$ git remote add orgin https://github.com/user/gen.git
fatal: remote orgin already exists.
** MacBook:magento user$ git push -u origin master**
fatal: ‘origin’ does not appear to be a git repository
fatal: Could not read from remote repository.

** Please make sure you have the correct access rights**
** and the repository exists.**

By the look of the message, did you miss

i changed it from my username to user.otherwise it is my username and github address is my repo link

I don’t understand what is meaning of origin and remote.

What’s your GitHub’s username? You have to replace username on that URL with your GitHub username and by the looks, gen is your repository’s name, so I assume it’s right.

Local repository is the git project that is in your machine. Remote repository (or just remote) is the same git project but on GitHub.

Check this image I got from git-tower.com. (Disregard the Subversion side):

http://www.git-tower.com/learn/content/01-git/01-ebook/01-command-line/07-appendix/03-from-subversion-to-git/centralized-vs-distributed.png

2 Likes

great illustration, thanks! so origin is our local working directory or in clone case the origin is where the source originated from, and remote is of course Git? Am i right? and i didn’t understand the “working copy” in the Git illustration.

So you got this, right?

Now, origin is an alias of your remote repository in your machine. In other words, origin is the word you use to identify your remote in your computer. Whenever you type origin in the command line, you are referencing to your remote.

By the way, you can set another keyword to be your remote name. It’s just conventional to use origin.

So if I am right origin is a short way to give your long url to hit profile and repo? If so, can we push our local file again and again to repo using origin?