User Tools

Site Tools


git_notes

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git_notes [2021/01/07 16:10] rajugit_notes [2023/05/05 14:55] (current) – [dokuwiki table syntax] admin
Line 1: Line 1:
 +===== workflow =====
 +==== Updating feature branch with the latest development branch ====
 +tags | bring feature branch up to date with development branch
 +
 +Situation 1:
 +  * User 1 raised a merge request to merge feature1 to development branch
 +  * Before the merge request is accepted, development branch is updated by User 2
 +
 +Situation 2:
 +  * Say you forked from development branch a while ago to work on a feature and created a branch called "feature1".
 +  * After a while, development branch might have progressed and may have new changes added to it.
 +
 +Task:
 +  * Bring the feature1 branch up to date with the latest development branch.
 +
 +Solution:
 +
 +Get the latest versions of development and feature branches in the local repository.
 +<code>
 +git checkout development
 +git pull
 +git checkout feature1
 +git pull
 +</code> 
 +
 +Merge development branch into the feature branch and resolve any conflicts that may arise.
 +<code>
 +git merge development
 +</code> 
 +Push the changes to the remote.
 +<code>
 +git push
 +</code> 
 +
 +Note:- The "git merge development" command works even if you have local changes not committed to feature1.
 +
 +===== Tasks =====
 +==== Initializing git for version control ====
 +<code>
 +git config --global user.name "Kamaraju S. Kusumanchi"
 +git config --global user.email "kamaraju@gmail.com"
 +git config --global push.default matching
 +git config --global alias.co checkout
 +git init
 +</code>
 +
 +Ref:- https://codemy.com/git
 +
 ===== dummy ===== ===== dummy =====
 +==== git resources ====
 +  * https://learngitbranching.js.org/ - Very good resource to learn git branching.
 +
 +==== stackoverflow answers I came across ====
 +  * ignore all directories with a specific name - https://stackoverflow.com/questions/1470572/ignoring-any-bin-directory-on-a-git-project
 +
 ==== show which branch is linked to which remote branch ==== ==== show which branch is linked to which remote branch ====
   * https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking   * https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking
Line 16: Line 70:
   * https://stackoverflow.com/questions/1395445/viewing-a-deleted-file-in-git - I got the answer from here. It also contains a few other alternate solutions.   * https://stackoverflow.com/questions/1395445/viewing-a-deleted-file-in-git - I got the answer from here. It also contains a few other alternate solutions.
  
-=== frequently used ===+===== git grep commands ===== 
 +==== dokuwiki table syntax ==== 
 +<code> 
 +git grep -i --all-match -e '\^.*\^' -e '|.*|' 
 +</code> 
 + 
 +==== Count number of lines in a file but exclude blank lines ==== 
 +<code> 
 +git grep -e "^" --and --not -e "^$" <file_name>  | wc -l 
 +</code> 
 + 
 +For example: 
 +<code> 
 +$ git grep -e "^" --and --not -e "^$" dummy_1510.txt  | wc -l 
 +27 
 +</code> 
 + 
 +===== Commits related ===== 
 +==== amend last commit ===== 
 + 
 +<code> 
 +export EDITOR=vim 
 +git commit --amend --author="Kamaraju S. Kusumanchi <kamaraju@gmail.com>" 
 +git config user.email "kamaraju@gmail.com" 
 + 
 +git config --get-all --show-scope user.email 
 +git config --get-all --show-origin user.email 
 +</code> 
 + 
 +===== Configuration related ===== 
 +==== configuration files ==== 
 +  * https://git-scm.com/docs/git-config#FILES - talks about which files 'git config' reads from. High information density. Easy to understand. 
 + 
 +===== git commands usage ===== 
 +==== git cherry-pick ==== 
 +<code> 
 +git cherry-pick <Commit1> <Commit2> <...> 
 +</code> 
 + 
 +Ref:- 
 +  * https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean 
 +  * https://learngitbranching.js.org/ -> Moving Work Around -> 1: Cherry-pick Intro 
 + 
 +===== frequently used =====
 ==== newly created repo ==== ==== newly created repo ====
 <code> <code>
Line 23: Line 120:
 </code> </code>
  
-==== push related ====+==== pull related ==== 
 +for git $\geq$ 2.23.0 
 +<code> 
 +git -c advice.detachedHead=false pull --rebase --autostash -v origin 
 +</code> 
 + 
 +for git $\leq$ 2.20.1
 <code> <code>
 git pull --rebase --autostash -v origin git pull --rebase --autostash -v origin
 </code> </code>
 +
 +used in | https://github.com/KamarajuKusumanchi/rutils/blob/master/bin/git-up
 +
git_notes.1610035851.txt.gz · Last modified: 2021/01/07 16:10 by raju