The git cherry-pick command is used to take the change introduced in a single Git commit and try to re-introduce it as a new commit on the branch you’re currently on. This can be useful to only take one or two commits from a branch individually rather than merging in the branch which takes all the changes.
History from master branch:
$ git branch
feature-text-branch
* master
$ git log --all --decorate --oneline --graph
* 7e365d0 (origin/feature-text-branch) sentences feature added
* 8792cfb (feature-text-branch) long phrases added
* 9dc9fbd text added
* ce52528 (HEAD, origin/master, origin/HEAD, master) Merge pull request #1 from n1653/super-feature
|\
| * 22efd50 super line added
|/
* 6dec4d5 +10
* f22f240 +9
* dce3cc0 +8
* d8fedcb +8
* 96154ba +7
* a86615b +6
* d32fdef +5
* f7d1d39 +4
* f34d14c +3
* 47e9fea +2
* 65f5aa9 001
* f86c164 Initial commit
History from feature-text-branch:
$ git checkout feature-text-branch
Switched to branch 'feature-text-branch'
$ git log --all --decorate --oneline --graph
* 7e365d0 (origin/feature-text-branch) sentences feature added
* 8792cfb (HEAD, feature-text-branch) long phrases added
* 9dc9fbd text added
* ce52528 (origin/master, origin/HEAD, master) Merge pull request #1 from n1653/super-feature
|\
| * 22efd50 super line added
|/
* 6dec4d5 +10
* f22f240 +9
* dce3cc0 +8
* d8fedcb +8
* 96154ba +7
* a86615b +6
* d32fdef +5
* f7d1d39 +4
* f34d14c +3
* 47e9fea +2
* 65f5aa9 001
* f86c164 Initial commit
Showing difference:
-
between ce52528 and 7e365d0
$ git diff ce52528 7e365d0
diff --git a/deleteme.001 b/deleteme.001
index 902ed6b..598e7c8 100644
--- a/deleteme.001
+++ b/deleteme.001
@@ -10,3 +10,18 @@
09
10
new_super_line
+text_01
+text_02
+text_03
+text_04
+new_super_wordy_line
+long_phrase_allowed_now_01
+long_phrase_allowed_now_02
+long_phrase_allowed_now_03
+long_phrase_allowed_now_04
+long_phrase_allowed_now_05
+long_phrase_allowed_now_06
+I can write sentences now. Several in a row. 01.
+I can write sentences now. Several in a row. 02.
+I can write sentences now. Several in a row. 03.
+
-
between ce52528 and 9dc9fbd
$ git diff ce52528 9dc9fbd
diff --git a/deleteme.001 b/deleteme.001
index 902ed6b..5d3cd62 100644
--- a/deleteme.001
+++ b/deleteme.001
@@ -10,3 +10,7 @@
09
10
new_super_line
+text_01
+text_02
+text_03
+text_04
Cherry-pick applied, log from master branch, note where the HEAD is:
$ git cherry-pick 9dc9fbd
[master 0d2d9af] text added
1 file changed, 4 insertions(+)
$ git log --all --decorate --oneline --graph
* 0d2d9af (HEAD, master) text added
| * 7e365d0 (origin/feature-text-branch) sentences feature added
| * 8792cfb (feature-text-branch) long phrases added
| * 9dc9fbd text added
|/
* ce52528 (origin/master, origin/HEAD) Merge pull request #1 from n1653/super-feature
|\
| * 22efd50 super line added
|/
* 6dec4d5 +10
* f22f240 +9
* dce3cc0 +8
* d8fedcb +8
* 96154ba +7
* a86615b +6
* d32fdef +5
* f7d1d39 +4
* f34d14c +3
* 47e9fea +2
* 65f5aa9 001
* f86c164 Initial commit
Log from feature-text-branch, note where the HEAD is:
$ git checkout feature-text-branch
Switched to branch 'feature-text-branch'
$ git log --all --decorate --oneline --graph
* 0d2d9af (master) text added
| * 7e365d0 (origin/feature-text-branch) sentences feature added
| * 8792cfb (HEAD, feature-text-branch) long phrases added
| * 9dc9fbd text added
|/
* ce52528 (origin/master, origin/HEAD) Merge pull request #1 from n1653/super-feature
|\
| * 22efd50 super line added
|/
* 6dec4d5 +10
* f22f240 +9
* dce3cc0 +8
* d8fedcb +8
* 96154ba +7
* a86615b +6
* d32fdef +5
* f7d1d39 +4
* f34d14c +3
* 47e9fea +2
* 65f5aa9 001
* f86c164 Initial commit
A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit.
Tag certain commit: git tag v1.0 22efd50
.
Push it: git push origin v1.0
.
Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).
Tag certain commit with annotation: git tag -a v1.1 fa1efd1 -m "release v1.1"
.
Push it: git push origin v1.1
.
History
$ git log --all --decorate --oneline --graph
* fa1efd1 (HEAD -> master, tag: v1.1, origin/master, origin/HEAD) text added
| * 7e365d0 (origin/feature-text-branch) sentences feature added
| * 8792cfb long phrases added
| * 9dc9fbd text added
|/
* ce52528 Merge pull request #1 from n1653/super-feature
|\
| * 22efd50 (tag: v1.0) super line added
|/
* 6dec4d5 +10
* f22f240 +9
* dce3cc0 +8
* d8fedcb +8
* 96154ba +7
* a86615b +6
…
if you need to make changes - you will generally want to create a branch:
$ git checkout v1.0 -b v1.0
Switched to a new branch 'v1.0'
$ git log --all --decorate --oneline --graph
* fa1efd1 (tag: v1.1, origin/master, origin/HEAD, master) text added
| * 7e365d0 (origin/feature-text-branch) sentences feature added
| * 8792cfb long phrases added
| * 9dc9fbd text added
|/
* ce52528 Merge pull request #1 from n1653/super-feature
|\
| * 22efd50 (HEAD -> v1.0, tag: v1.0) super line added
|/
* 6dec4d5 +10
* f22f240 +9
…
$ git branch --list
master
* v1.0
-
Patterns read from the command line for those commands that support them.
-
Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.
-
Patterns read from $GIT_DIR/info/exclude.
-
Patterns read from the file specified by the configuration variable core.excludesFile
$ echo "
# secrets
secrets*" >> ./.gitignore
$ git add ./secrets_01.conf
The following paths are ignored by one of your .gitignore files:
secrets_01.conf
Use -f if you really want to add them.
$ git add ./*
The following paths are ignored by one of your .gitignore files:
secrets_01.conf
Use -f if you really want to add them.
Protocol | Description |
---|---|
SSH |
SSH simple, encrypted. SSH is that it doesn’t support anonymous. Predicaments with proxy may occur. |
HTTP |
Encrypted. Providing your credentials is sometimes more complicated than using keys over SSH. |
GIT |
Unencrypted, no authentication. Complicated. The fastest network transfer protocol available. Usually works as read-only along with HTTP/SSH for push. |
Local |
To change protocol clone repository and start working with the local copy:
$ git clone https://github.com/n1654/devops-school
$ cd ./devops-school/
$ git remote -v
origin https://github.com/n1654/devops-school (fetch)
origin https://github.com/n1654/devops-school (push)
Chage
$ git remote set-url origin git+ssh://git@github.com/n1654/devops-school
$ git remote -v
origin git+ssh://git@github.com/n1654/devops-school (fetch)
origin git+ssh://git@github.com/n1654/devops-school (push)
Download and install [Git Credential Manager for Windows](https://github.com/Microsoft/Git-Credential-Manager-for-Windows)
> git config --list | findstr "cred"
credential.helper=manager
osxkeychain - is working by default
% git config --list
credential.helper=osxkeychain
user.name=Dmitrii Overchenko
user.email=dov@ubiqube.com
Generate keys:
$ ssh-keygen -o
Generating public/private rsa key pair.
Enter file in which to save the key (/home/centos/.ssh/id_rsa): git-devops-school
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in git-devops-school.
Your public key has been saved in git-devops-school.pub.
change permissions:
$ chmod 400 ./git-devops-school.pub
verify protocols:
$ cd devops-school
$ git remote -v
origin git+ssh://git@github.com/n1654/devops-school (fetch)
origin git+ssh://git@github.com/n1654/devops-school (push)
start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
Agent pid 23560
Add your SSH private key to the ssh-agent
$ ssh-add ../git-devops-school
Login
$ ssh -T git@github.com
Hi n1654! You've successfully authenticated, but GitHub does not provide shell access.
Now you can push without credentials prompt git push origin master
If you want to contribute to an existing project to which you don’t have push access, you can “fork” the project. When you “fork” a project, GitHub will make a copy of the project that is entirely yours; it lives in your namespace, and you can push to it.
-
Fork the project.
-
Create a topic branch from master.
-
Make some commits to improve the project.
-
Push this branch to your GitHub project.
-
Open a Pull Request on GitHub.
-
Discuss, and optionally continue committing.
-
The project owner merges or closes the Pull Request.
-
Sync the updated master back to your fork.