tips:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tips:git [2016/07/18 07:13] – [new remote branch] scipiotips:git [2019/03/13 09:30] (current) – [apache git] scipio
Line 1: Line 1:
 ====== GIT ====== ====== GIT ======
 +
 +===== credentials  and config =====
 +
 +<file ini ~/.netrc>
 +machine git.csgalileo.org
 +login blabla
 +password blabla
 +</file>
 +
 +<file ini ~/.gitconfig>
 +[user]
 +    name = Stefano Scipioni
 +    email = blabla
 +[core]
 +    autocrlf = input
 +    #safecrlf = true
 +    editor = vim
 +[http]
 +    sslverify = false
 +[alias]
 +    co = checkout
 +    ci = commit
 +    st = status
 +    br = branch
 +    hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
 +    type = cat-file -t
 +    dump = cat-file -p
 +[push]
 +    default = simple
 +[color]
 +    ui = auto
 +</file>
 +
  
 ===== New repo ===== ===== New repo =====
Line 13: Line 46:
 </code> </code>
  
 +===== change origin =====
 +
 +<code bash>
 +git remote -v
 +</code>
 +
 +<code bash>
 +git remote set-url origin http://git.csgalileo.org/livenet-server.git
 +</code>
 +
 +check origin
 +<code bash>
 +git remote show origin
 +</code>
 +
 +if prune needed (on server restart apache if dav is used)
 +<code bash>
 +git remote prune origin
 +</code>
 +
 + 
 +<code bash>
 +git push --set-upstream origin master
 +</code>
 +
 +
 +
 +
 +===== create branch with current changes =====
 +
 +<code>
 +git checkout -b newBranch
 +</code>
 +
 +===== tag =====
 +
 +<code>
 +git tag -a v1.1 -m "versione 1.1"
 +git push origin v1.1
 +</code>
 ===== new remote branch ===== ===== new remote branch =====
  
Line 23: Line 96:
 </code> </code>
  
-create remotly+create or update remotly 
 +<code> 
 +git push --set-upstream origin [name_of_branch] 
 +</code> 
 + 
 +view remote branches 
 +<code> 
 +git fetch -v 
 +</code> 
 + 
 +fetch remote branches 
 +<code> 
 +git checkout -b [branch] origin/[branch] 
 +</code> 
 + 
 +===== delete remote branch ===== 
 + 
 +<code bash> 
 +git push origin --delete [branch] 
 + 
 +# and locally 
 +git branch -d [branch] 
 +</code> 
 + 
 +===== rename branch (local and remote) ===== 
 + 
 + 
 +<code> 
 +git branch -m new-name 
 + 
 +# Delete the old-name remote branch and push the new-name local branch. 
 +git push origin :old-name new-name 
 + 
 +# Reset the upstream branch for the new-name local branch. 
 +git push origin -u new-name 
 +</code> 
 +===== Preserve specific files while merging ===== 
 + 
 +start by defining a merge driver that would always favor our current version of the file 
 +<code> 
 +git config --global merge.ours.driver true 
 +</code> 
 + 
 +into repo mark examplefile.json to use that driver instead of the standard one:  
 +<code> 
 +echo 'examplefile.json merge=ours' >> .gitattributes 
 +</code> 
 + 
 + 
 +=====  integrate changes from one branch into another branch ===== 
 + 
 +==== merging ==== 
 + 
 +from feature branch to master 
 +<code bash> 
 +git checkout feature 
 +git merge master 
 +</code> 
 + 
 +==== or rebasing ==== 
 + 
 +<code bash> 
 +git checkout feature 
 +git rebase -i master 
 + 
 +# if remote feature is present force push on origin 
 +git push --force origin feature 
 +</code> 
 + 
 +==== rebase remote branch (or original fork) with local branch ==== 
 + 
 +add forked repo if none (git remote -v) 
 +<code> 
 +git remote add upstream https://github.com/pjreddie/darknet.git 
 +</code> 
 + 
 +rebase remote on master 
 +<code> 
 +git fetch upstream 
 +git checkout master 
 +git merge upstream/master 
 +git push 
 +</code> 
 +==== merge specific commit from branch to another ==== 
 + 
 +<code bash> 
 +git co <branch-target> 
 +git cherry-pick <commit> 
 +</code> 
 + 
 +===== Home Assistant ===== 
 + 
 +<code bash> 
 +git clone https://github.com/scipioni/home-assistant.git 
 +cd home-assistant 
 +git remote add upstream https://github.com/home-assistant/home-assistant.git 
 +git pull upstream dev 
 +</code> 
 + 
 +===== apache git ===== 
 + 
 +<code bash> 
 +apt install apache2 
 +a2enmod dav_lock dav dav_fs macro 
 +systemctl restart apache2 
 +</code> 
 + 
 +===== submodule ===== 
 <code> <code>
-git push origin [name_of_your_new_branch]+cd <submodule> 
 +git checkout master 
 +git branch -u origin/master master 
 +cd <parent> 
 +git config -f .gitmodules submodule.<submodule>.branch master
 </code> </code>
  • tips/git.1468818837.txt.gz
  • Last modified: 2016/07/18 07:13
  • by scipio