PositiveGuy
PositiveGuy

Reputation: 47763

Clone after initial Push?

If I just performed an initial push to my new git repo (git push -u origin master), I assume I need to set my local code as a working copy by performing a clone right after? Or is it basically already "cloned" or what I mean is it's already flagged as a "working copy" after performing your first push since this is to a new repo I created..not an existing? Just want to be sure, I'm fairly new to Git.

Upvotes: 0

Views: 44

Answers (3)

D-side
D-side

Reputation: 9495

Before I start explaining, I need you to understand what 3 branches are at work here:

  • Local master
  • Remote master (at origin)
  • Local origin/master (a local "reflection" of a remote master, typically not for direct use)

Before you pushed, you only had a local master and nothing else, empty remote.

git push -u origin master

This attempts to push your local master branch to a remote branch with the same name (master) in remote repository called origin (a common name for a remote, even used by default when cloning).

If successful, Git creates a new local branch called origin/master and sets your local master to "track changes" (because of -u as in "upstream") to origin/master: any changes to that branch are assumed as "should be merged into master as well".

This is only important when you'll be pulling down the changes from your remote repository. When you're on a master branch, it will first fetch commits to origin/master, and then examine what branch master is tracking. Having found origin/master it would attempt to merge it with your local master. pull does quite a lot inside.

After this your local master and origin/master should be on the same commit and your remote master should look exactly the same as your local one. So you shouldn't need to do anything.

To understand branching better, I strongly recommend this interactive tutorial.

Upvotes: 2

Makoto
Makoto

Reputation: 106470

There's no need to clone anything on the machine that you've pushed from. You've essentially have a clone of the remote repository; it just happens to be the case that it's the exact same as your local repository.

When you clone a repository, that implies that you don't have the code currently present on your machine. In your scenario, you already have the code, so you don't need to do any cloning.

Upvotes: 0

Jörn Hees
Jörn Hees

Reputation: 3428

If i understand this right, you're now in the alread "cloned" state:

If you successfully ran a git push -u origin master then you ran it from the local repository.

By providing the -u option to the push, git will remember that your branch is meant to track the one on origin, which is similar to what you get by cloning a remote repository.

Upvotes: 0

Related Questions