To get the repository’s tags issue:
$ git fetch --tags [branch_name]
To add a tag to the top commit:
$ git tag -a
Note: this will open an editor screen where you can insert a description message (similar to a commit)
To add a tag to a specific commit:
$ git tag -a [tag_name] [commit_hash]
To push a tag to remote:
$ git push [repo_name] --tags # for all tags
$ git push [repo_name] [tag_name] # for a single tag named 'tag_name'
To merge a tagged commit:
$ git merge [tag_name]
See also: how to see the information of the repo’s branches from the CLI, including your tags in this post
In case you need to work with more than one remote repositories, chances are you need to add one of them (origin comes as a default).
$ git remote add remote_name https://github.com/user/repo.git
Choose the remote_name as you wish and grab the repo URL from github.
You may also be interested in Selecting remote repository on git or maybe if you need to rename your remote, you might want to read how to rename a remote repository
For a little more information, visit: https://help.github.com/articles/adding-a-remote/
Issue this command to change the author of the very last commit message:
$ git commit --amend --author="John Doe <email@example.com>"
To change the author of your config file:
$ git config --global user.name "John Doe"
$ git config --global user.email "firstname.lastname@example.org"
For more commands, visit https://www.git-tower.com/learn/git/faq/change-author-name-email
For more git quick commands, go to https://quicktechrefs.wordpress.com/?s=git
Git has a wonderful tool that allows you to create patches of the commits in the tree of your project: git format-patch.
$ git format-patch [<options>] [<since> | <revision-range>]
More information can be seen via man page:
$ git format-patch -h
$ man git format-patch
$ git format-patch -N
This command generates one .patch file for each of the N commits on the top of your tree. Example:
$ git format-patch -1
Generates a .patch file for the commit on the top of your tree. Increase the number to get one file per commit (for the top 3 commits, use ‘-3’).
To apply the patch, use
$ git am [your-patch].patch
Egon Willighagen shares in his GitHub Tip: download commits as patches how to save a commit from github into a .patch file:
“By appending .patch to the commit URL, a commit can easily be downloaded as patch.”
Example using commit # 005cdb
Quick shot: To remove a remote branch on your git repo:
git push [remote-name] --delete [branch-name]
dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git branch -r
dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git push origin --delete test
remote: Updating references: 100% (1/1)
- [deleted] test
I recently started to work with two remote repositories on git, and then faced a probably common scenario: check the state of each repository (say ‘origin‘ and ‘vertiv‘).
A 20 minute search provided me the best solution:
$ git branch -u [remote-repo]/[branch]
In this case, origin/master is ahead of vertiv/master by 2 commits, and my local is sync’ed with vertiv/master.
The docs read:
-u <upstream>, –set-upstream-to=<upstream>
Set up <branchname>’s tracking information so <upstream> is considered <branchname>’s upstream branch. If no <branchname> is
specified, then it defaults to the current branch.