Git: Pulling from Remote by Tag
I’m a beginner at git and have been testing a couple of commands on my local computer by creating a local repository to pull and push from and to.
I setup a bare repository in ‘project’ and cloned two users: ‘user1’ and ‘user2’ from it. The project currently has the files ‘one.txt’, ‘two.txt’ etc. and a few commits tagged with ‘v1.0’, ‘v2.0’ etc. associated with adding a new “#.txt” file.
- Versioning SQL Server database
- Mercurial: Merging one file between branches in one repo
- Visual Source Safe --> TFS Migration
- Which NetBeans projects files should go into source control?
- How can I provide a 2-way mirror of a Git repository with another SCM? (bzr, hg etc)
- Can I create a empty branch on a remote using git? Is there Anyway I can atleast create a local empty branch and push it to remote?
However, when I attempt to create a new git working directory in a new folder ‘tmp’, adding the project as a remote repository (tmp is not a clone), and pulling, I get the error:
$ git pull ../project v1.0 $ fatal: 'v1.0' does not appear to be a git repository $ fatal: The remote end hung up unexpectedly
This doesn’t happen when I simply try to pull the master branch from project, so I assume I have permissions to pull. What’s going on?
2 Solutions collect form web for “Git: Pulling from Remote by Tag”
All you want to do is create another clone. Unless you have good reason not to do it, it will duplicate all history (don’t worry, it’s usually <10% the size of an svn repo and often smaller than the working dir due to compression).
Create your first repo:
mkdir myrepo cd !$ git init echo one > one.txt git add -A git commit "my first commit" git tag v1.0 echo two > two.txt git add -A git commit "my second commit" git tag v2.0
Create a simulated central repo:
cd .. mkdir centralrepo cd !$ git init --bare # don't want to have a working directory here cd -
Create a simulated coworker repo:
mkdir coworkerrepo cd !$ git init
Tell your repo where the central repo is
cd ../myrepo git remote add origin ../centralrepo
Tell your coworker’s repo where the central repo is
cd ../coworkerrepo git remote add origin ../centralrepo
Publish your work to the central repo:
cd - # useful shortcut for flipping between two dirs (works for git checkout and branches too) git push origin master
puts up the master reference and the commits within, but not tags. For tags, do this:
git push origin v1.0 git push origin v2.0
or just push up all tags in your repo with
git push origin --tags
you can now check that the remote has those tags and references with
git remote -v show origin
switch to your coworker’s repository and get those changes:
cd - git fetch # will update tracking branches and tags git merge origin/master # fast-forward master branch to what the remote tracking branch is pointing to
the two operations
merge are done at the same time with
pull. So you could have done this instead
git pull origin master
So tags get fetched. This is implied when you realize that pull is fetch and merge (or rebase if you want) put together.
You already have the tags in your history. You can use
git tag -l to list all available tags, and you can
git checkout to them at any time.
git checkout v1.0