Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Branch,Tag: How to get a specific release of a code?

I'm new to Git hub and I got confused about the concept of tag and branch(explained here) I would like to get an stable version of PhantomJS(version 2.1.0) from git hub. But I don't understand if I should do:

git checkout master
git remote add upstream https://github.com/ariya/phantomjs.git
git fetch upstream
git rebase --onto tags/2.1.0 upstream/master master

or

git init
git remote add -t 2.1 -f origin https://github.com/ariya/phantomjs.git
git checkout 2.1

Would you please explain me which one and why?

like image 358
Alex Avatar asked Jul 14 '16 21:07

Alex


People also ask

How do I pull code from GitHub tag?

Checkout Git Tag To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.

Are GitHub tags be branch specific?

Tags and branch are completely unrelated, since tags refer to a specific commit, and branch is a moving reference to the last commit of a history.

How do I pull a specific commit?

How do I pull a specific commit? The short answer is: you cannot pull a specific commit from a remote. However, you may fetch new data from the remote and then use git-checkout COMMIT_ID to view the code at the COMMIT_ID .

How do I create a release tag in GitHub?

On GitHub.com, navigate to the main page of the repository. To the right of the list of files, click Releases . Click Draft a new release. Click Choose a tag, type a version number for your release, and press Enter. Alternatively, select an existing tag.

What is the difference between branches and tags in Git?

Branches are dynamic and code can be added to them. A tag is most typically used to mark a particular point in the commit ancestry chain. A branch is an active line of development whereas a tag is a reference to a specific commit on any branch.

What is a Git tag?

#git #tags. Tags are a simple aspect of Git, they allow you to identify specific release versions of your code. You can think of a tag as a branch that doesn't change. Once it is created, it loses the ability to change the history of commits.

Why can’t I download a specific branch of a GitHub repository?

This is because, even if you’re switched to a branch on the website, Github only gives you the URL to download the repo from. It does not tell you how you should download it. If you take this URL, and run git clone, it will download the default branch, usually master.


Video Answer


2 Answers

You should just clone the repository and then checkout the tag:

$ git clone https://github.com/ariya/phantomjs.git
$ cd phantomjs
$ git checkout 2.1

Keep in mind that being on a tag, you cannot commit any local change you would make. For that, you must be on a branch. What can be confusing is that the command is git checkout for both branches and tags.

like image 85
Frodon Avatar answered Sep 17 '22 15:09

Frodon


I am not sure if I understood your question correctly but I will try to answer on it:

Git stores data about all changes that made in code (this include data about branches and tags) When you clone a repository you will get complete history for that repository

So, git clone https://github.com/ariya/phantomjs.git will clone project
If you have forked project you can do
git clone https://github.com/<YOUR_USERNAME>/phantomjs.git

Now change directory to phantomjs: cd phantomjs/

To see history you can execute git log or git log --oneline --decorate --graph for prettier view

To list all tags on repository execute
git tag

Finally, to create branch with tag 2.1.0 execute
git checkout 2.1.0 -b v2.1.0
After this you will have two branches master and v2.1.0

I hope this helps

like image 42
djm.im Avatar answered Sep 18 '22 15:09

djm.im