Difference between revisions of "Linux command: git"
Rafahsolis (talk | contribs) |
Rafahsolis (talk | contribs) m (→Cheat Sheet) Tag: visualeditor |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | == Install== | + | ==Install== |
sudo add-apt-repository ppa:git-core/ppa -y | sudo add-apt-repository ppa:git-core/ppa -y | ||
sudo apt-get update | sudo apt-get update | ||
sudo apt-get install git | sudo apt-get install git | ||
git --version | git --version | ||
| − | == Clone == | + | ==Clone== |
git clone <repository_path> | git clone <repository_path> | ||
| − | === Clone with submodules === | + | ===Clone with submodules=== |
git clone --recurse-submodules -j8 git@git.rra.lan:python/pilaf/Converter.git | git clone --recurse-submodules -j8 git@git.rra.lan:python/pilaf/Converter.git | ||
| − | |||
| − | == add/commit/push == | + | *Note: -j8 increases performance cloning up to 8 submodules at a time |
| + | |||
| + | To update repositories with submodules use: | ||
| + | git pull --recurse-submodules | ||
| + | |||
| + | ==add/commit/push== | ||
git add . | git add . | ||
git add -A | git add -A | ||
| Line 17: | Line 21: | ||
git push origin master | git push origin master | ||
| − | == Branching == | + | ==Branching== |
git checkout -b <branch_name> | git checkout -b <branch_name> | ||
git merge | git merge | ||
| − | === git Successful Feature Branching Workflow === | + | ===git Successful Feature Branching Workflow=== |
Onece you have cloned the master repository: | Onece you have cloned the master repository: | ||
| − | * Create a branch for each feature | + | |
| − | * Merge branches with --no-ff | + | *Create a branch for each feature |
| + | *Merge branches with --no-ff | ||
git checkout -b <branch_name> | git checkout -b <branch_name> | ||
| Line 34: | Line 39: | ||
git reset --hard f414f31 | git reset --hard f414f31 | ||
| − | == Undo last changes == | + | ==Undo last changes== |
git checkout -- . | git checkout -- . | ||
| − | == add remote == | + | ==add remote== |
git remote add <repository_name> <repository_path> | git remote add <repository_name> <repository_path> | ||
| − | == list remote == | + | ==list remote== |
git remote -v | git remote -v | ||
| − | == Modify remote url == | + | ==Modify remote url== |
git remote set-url origin <new_url/new_repository.git | git remote set-url origin <new_url/new_repository.git | ||
| − | == remove remote == | + | ==remove remote== |
git rm <repository_name> | git rm <repository_name> | ||
| − | == pull/push == | + | ==pull/push== |
git push <repository_name> | git push <repository_name> | ||
git pull <repository_name> | git pull <repository_name> | ||
| Line 56: | Line 61: | ||
git push --all origin | git push --all origin | ||
| − | === Tags === | + | ===Tags=== |
To fetch tags: | To fetch tags: | ||
git fetch --tags | git fetch --tags | ||
| Line 62: | Line 67: | ||
git push origin --tags | git push origin --tags | ||
| − | === Full copy of remote repository: === | + | ===Full copy of remote repository:=== |
<nowiki>#!/bin/bash | <nowiki>#!/bin/bash | ||
| − | for branch in `git branch -r | grep -v HEAD | grep -v master`; do | + | for branch in `git branch -r | grep -v HEAD | grep -v master`; do |
| − | + | echo ${branch##*/} $branch | |
| − | done | + | done |
| − | git fetch --all | + | git fetch --all |
| − | git pull -v</nowiki> | + | git pull -v</nowiki> |
| − | == Add .gitignore == | + | ==Add .gitignore== |
Add the file to the git folder | Add the file to the git folder | ||
To stop following and delete the files that were allready being tracked: | To stop following and delete the files that were allready being tracked: | ||
| Line 77: | Line 82: | ||
git commit -m ".gitignore now working" | git commit -m ".gitignore now working" | ||
| − | # To undo git rm --cached filename use: git add filename | + | #To undo git rm --cached filename use: git add filename |
| − | == git config == | + | |
| + | ==git config== | ||
git config --global push.default [matching | simple] | git config --global push.default [matching | simple] | ||
git config --global user.name "Nombre Apellido" | git config --global user.name "Nombre Apellido" | ||
git config --global user.email "user@domain.com" | git config --global user.email "user@domain.com" | ||
| − | === Self Signed Certificates | + | |
| + | ===Default editor=== | ||
| + | <syntaxhighlight lang="bash"> | ||
| + | git config core.editor "nano -w" | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==Self Signed Certificates== | ||
To allow cloning and pushing to a git repository over https whit a self signed certificate you must configure: | To allow cloning and pushing to a git repository over https whit a self signed certificate you must configure: | ||
git config --global http.sslVerify false | git config --global http.sslVerify false | ||
| Line 88: | Line 100: | ||
git -c http.sslVerify=false clone https://domain.com/path/to/git | git -c http.sslVerify=false clone https://domain.com/path/to/git | ||
| − | == assume-unchanged == | + | ==assume-unchanged== |
This will make git to stop tracking changes on <file> | This will make git to stop tracking changes on <file> | ||
git update-index --assume-unchanged <file> | git update-index --assume-unchanged <file> | ||
| Line 97: | Line 109: | ||
To view which files are not being tracked: | To view which files are not being tracked: | ||
git ls-files -v|grep '^h' | git ls-files -v|grep '^h' | ||
| − | == Set upstream branch == | + | ==Set upstream branch== |
git branch --set-upstream-to=origin/master | git branch --set-upstream-to=origin/master | ||
| − | == Change last commit == | + | ==Change last commit== |
git commit --amend | git commit --amend | ||
| − | == Change older commit messages == | + | ==Change older commit messages== |
git rebase -i HEAD~n | git rebase -i HEAD~n | ||
Replace pick with reword before each commit message you want to change.<br /> | Replace pick with reword before each commit message you want to change.<br /> | ||
| Line 111: | Line 123: | ||
| + | == Create git aliases == | ||
| + | === count-lines Alias === | ||
| + | <syntaxhighlight lang="bash"> | ||
| + | git config --global alias.count-lines "! git log --author=\"\$1\" --pretty=tformat: --numstat | awk '{ add += \$1; subs += \$2; loc += \$1 - \$2 } END { printf \"added lines: %s, removed lines: %s, total lines: %s\n\", add, subs, loc }' #" | ||
| + | </syntaxhighlight> | ||
| − | == Cheat Sheet == | + | ==Cheat Sheet== |
http://wiki.herrerosolis.com/images/4/46/Git-cheat-sheet.pdf | http://wiki.herrerosolis.com/images/4/46/Git-cheat-sheet.pdf | ||
Latest revision as of 13:49, 9 April 2024
Install
sudo add-apt-repository ppa:git-core/ppa -y sudo apt-get update sudo apt-get install git git --version
Clone
git clone <repository_path>
Clone with submodules
git clone --recurse-submodules -j8 git@git.rra.lan:python/pilaf/Converter.git
- Note: -j8 increases performance cloning up to 8 submodules at a time
To update repositories with submodules use:
git pull --recurse-submodules
add/commit/push
git add . git add -A git commit -m "Message of commit" git commit -am "Message" # add and commit in one line git push origin master
Branching
git checkout -b <branch_name> git merge
git Successful Feature Branching Workflow
Onece you have cloned the master repository:
- Create a branch for each feature
- Merge branches with --no-ff
git checkout -b <branch_name>
Write your new code Switch to the master branch to merge
git merge --no-ff <brach_to_merge_name>
Set the current branch to specific commit:
git reset --hard f414f31
Undo last changes
git checkout -- .
add remote
git remote add <repository_name> <repository_path>
list remote
git remote -v
Modify remote url
git remote set-url origin <new_url/new_repository.git
remove remote
git rm <repository_name>
pull/push
git push <repository_name> git pull <repository_name>
To push all branches:
git push --all origin
Tags
To fetch tags:
git fetch --tags
To push tags:
git push origin --tags
Full copy of remote repository:
#!/bin/bash
for branch in `git branch -r | grep -v HEAD | grep -v master`; do
echo ${branch##*/} $branch
done
git fetch --all
git pull -v
Add .gitignore
Add the file to the git folder To stop following and delete the files that were allready being tracked:
git rm -r --cached . git add . git commit -m ".gitignore now working"
- To undo git rm --cached filename use: git add filename
git config
git config --global push.default [matching | simple] git config --global user.name "Nombre Apellido" git config --global user.email "user@domain.com"
Default editor
git config core.editor "nano -w"
Self Signed Certificates
To allow cloning and pushing to a git repository over https whit a self signed certificate you must configure:
git config --global http.sslVerify false
or
git -c http.sslVerify=false clone https://domain.com/path/to/git
assume-unchanged
This will make git to stop tracking changes on <file>
git update-index --assume-unchanged <file>
To include again this file run:
git update-index --no-assume-unchanged <file>
To view which files are not being tracked:
git ls-files -v|grep '^h'
Set upstream branch
git branch --set-upstream-to=origin/master
Change last commit
git commit --amend
Change older commit messages
git rebase -i HEAD~n
Replace pick with reword before each commit message you want to change.
Save and close the commit list file.
In each resulting commit file, type the new commit message, save the file, and close it.
git push --force
Create git aliases
count-lines Alias
git config --global alias.count-lines "! git log --author=\"\$1\" --pretty=tformat: --numstat | awk '{ add += \$1; subs += \$2; loc += \$1 - \$2 } END { printf \"added lines: %s, removed lines: %s, total lines: %s\n\", add, subs, loc }' #"
Cheat Sheet
http://wiki.herrerosolis.com/images/4/46/Git-cheat-sheet.pdf