简体   繁体   中英

How do I push GIT changes from one clone to another?

I'm just getting started with git. I've spent the past 8 hours reading every guide and tutorial online. I'm still somewhat of a newbie to git, so please forgive if this question is dumb, or maybe I'm even asking the wrong question. Just know I've spent a fair amount of time researching this before I asked here.

I have two environments: TEST & DEV. So far we've literally just been copying and pasting the updated files via FTP. I know this is bad. So today I wanted to get this under git control.

So... I backed up all my files. SSHed into TEST and performed git init , git add . , git commit -m "First Commit" , and finally git push . Then I opened up a new Terminal window and SSHed into DEV. In dev I created a new empty folder and performed git clone username@TEST:/path .

Everything seemed fine.

Then I added some new files to DEV and tried to push the changes up to TEST and it's just not working. When I go into TEST and type git status it shows my commits, but the new files aren't there.

Question: How do I push files up from my DEV clone to TEST?

Note: I don't have any branches or anything really complicated. This is a basic set up. Am I doing this wrong/dumb?

git status doesn't show commits - it shows the status of the working copy .

On DEV , you should git add each file, then git commit , then finally git push . This will put your changes into the repository ( .git directory) on TEST .

If you've already done that, you need to do a git merge (or git pull , which is the equivalent of git fetch and git merge ) on test to get the latest changes into the working copy there - the changesets are in the branch, but your checkout is out of date.

Ok, so if you want to push stuff from a repository (TEST) to another repository (DEV), you have to create a new REMOTE.

When you do PUSH or PULL, you're transfering content between your repository and one of his REMOTE. The default remote is known as ORIGIN, but you can create new remote as much as needed.

git remote add REMOTE_NAME REMOTE_URL_OR_PATH

You can list remote with:

git remote -v

And you can push to a specific remote like so:

git push REMOTE_NAME BRANCH_NAME

or pull:

git pull REMOTE_NAME BRANCH_NAME

Some extra documentation: http://help.github.com/remotes/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM