linux_wiki: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
linux_wiki:git [2018/05/24 09:16]
billdozor [Upstream Repo Sync]
linux_wiki:git [2020/01/10 18:29] (current)
billdozor [Extra Characters in git diff]
Line 4: Line 4:
  
 Useful git commands when managing git repos. Useful git commands when managing git repos.
 +
 +Official site: https://git-scm.com/
  
 **Checklist** **Checklist**
Line 42: Line 44:
 \\ \\
 Verify version<code bash>git --version</code> Verify version<code bash>git --version</code>
- 
----- 
- 
-===== Source ===== 
- 
-Newer versions of Git can be installed from source. 
- 
-TODO 
  
 ---- ----
Line 55: Line 49:
 ====== Initial Git Config Setup ====== ====== Initial Git Config Setup ======
  
-Setup your name for commits:+Setup your user name for commits:
 <code bash> <code bash>
 git config --global user.name "USERNAME" git config --global user.name "USERNAME"
Line 85: Line 79:
 </code> </code>
  
----- +\\ 
- +Disable https verify for self signed certs on a single cloned repo<code bash>git config http.sslVerify false</code>
-====== Clone Repos ====== +
- +
-Download an existing project via URL<code bash>git clone URL</code>+
  
 \\ \\
-Download an existing project via HTTPS URL and do not verify ssl cert for self signed<code bash>git -c http.sslVerify=false clone https://URL</code>+Alternatively, configure git to trust self signed certs: https://stackoverflow.com/questions/9072376/configure-git-to-accept-a-particular-self-signed-server-certificate-for-a-partic
  
 ---- ----
  
-====== Configure Repos ======+====== Create/Clone Repos ======
  
-Disable https verify for self signed certs on single cloned repo<code bash>git config http.sslVerify false</code>+Create a new local project (to be pushed up to a repo later)<code bash>git init <project-name></code>
  
 \\ \\
-Alternatively, configure git to trust self signed certs: https://stackoverflow.com/questions/9072376/configure-git-to-accept-a-particular-self-signed-server-certificate-for-a-partic+Download an existing project via URL<code bash>git clone URL</code> 
 + 
 +\\ 
 +Download an existing project via HTTPS URL and do not verify ssl cert for self signed<code bash>git -c http.sslVerify=false clone https://URL</code>
  
 ---- ----
Line 140: Line 134:
       * View recent commits with diff details<code bash>git log -p</code>       * View recent commits with diff details<code bash>git log -p</code>
       * Retrieve the commit SHA hash from the above and revert that push<code bash>git revert <SHA></code>       * Retrieve the commit SHA hash from the above and revert that push<code bash>git revert <SHA></code>
 +
 +----
 +
 +====== Exclude Files from Tracking ======
 +
 +A plain text file called '.gitignore' in the project root excludes files and directories from tracking by git.
 +
 +Full documentation here: https://git-scm.com/docs/gitignore
 +
 +\\
 +Example .gitignore<code bash># Git ignore file - comments are allowed
 +__pycache__/
 +*.log
 +tmp/</code>
 +  * Do not track any files that
 +    * Are inside a __pycache__ directory
 +    * End in .log
 +    * Are inside a tmp directory
 +
 +\\
 +List all ignored files in the current project<code bash>git ls-files --other --ignored --exclude-standard</code>
  
 ---- ----
Line 282: Line 297:
  
 ---- ----
 +
 +===== Deleting Branches =====
 +
 +Delete a remote branch<code bash>git push origin --delete <branch-name></code>
 +
 +\\
 +Delete a local branch<code bash>git branch --delete <branch-name></code>
 +
 +\\
 +Prune remote list if remote branches were deleted by someone else<code bash>git remote prune origin</code>
 +
 +----
 +
  
 ===== Upstream Repo Sync ===== ===== Upstream Repo Sync =====
  
 If your cloned repo is a fork, you will want to keep it synced with the upstream project from time to time. If your cloned repo is a fork, you will want to keep it synced with the upstream project from time to time.
 +
 +==== Add Upstream Source ====
 +
 +Adding the upstream repo to your local cloned fork only needs to be done one time.
  
   * In the terminal, navigate to the directory of the cloned repo.   * In the terminal, navigate to the directory of the cloned repo.
Line 294: Line 326:
  
   * Verify upstream was added<code bash>git remote -v</code>   * Verify upstream was added<code bash>git remote -v</code>
 +
 +==== Syncing Fork to Upstream ====
  
   * Fetch upstream's commits<code bash>git fetch upstream</code>   * Fetch upstream's commits<code bash>git fetch upstream</code>
Line 302: Line 336:
  
   * Push local changes to your fork on github<code bash>git push origin master</code>   * Push local changes to your fork on github<code bash>git push origin master</code>
 +
 +----
 +
 +====== Troubleshooting ======
 +
 +Fixing different git issues.
 +
 +===== Extra Characters in git diff =====
 +
 +* Fix/remove 'ESC[xxx' characters in git diff<code bash>git config --global core.pager "less -R"</code>
 +\\
 +
 +* Fix/remove '^M' characters in git diff<code bash>git config --global core.pager "tr -d '\r' | less -REX"</code>
  
 ---- ----
  
  • linux_wiki/git.1527167806.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)