Difference between revisions of "Git"

From wikieduonline
Jump to navigation Jump to search
(Created page with "== Activities == === Git Installation === # Download Git from https://git-scm.com/downloads. # Install Git. (MacOS: <code>brew install git</code>) === Copy an existing remote...")
 
Tags: Mobile web edit, Mobile edit
 
(71 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
<code>[[wikipedia:git (software)|git]]</code> ([[2005]]) is a distributed [[revision control software]].
 +
 +
* [[git init]]
 +
* [[git bisect]]
 +
* [[git clone]]
 +
* [[git config]]
 +
* [[git log]]
 +
* [[git pull]]
 +
* [[git push]]
 +
* [[git fetch]]
 +
* [[git remote]]
 +
* [[git show]]
 +
* [[git checkout]]
 +
* [[git switch]]
 +
 
== Activities ==
 
== Activities ==
 
=== Git Installation ===
 
=== Git Installation ===
 
# Download Git from https://git-scm.com/downloads.
 
# Download Git from https://git-scm.com/downloads.
# Install Git. (MacOS: <code>brew install git</code>)
+
# Install Git. (MacOS: <code>[[brew install git]]</code>)
 +
# apt install git or apt install [[git-all]]
  
 
=== Copy an existing remote repository ===
 
=== Copy an existing remote repository ===
Line 8: Line 24:
 
#* Select a local folder to copy the repository into, or create a new folder if you prefer. The repository will be copied as a subdirectory of the selected folder.
 
#* Select a local folder to copy the repository into, or create a new folder if you prefer. The repository will be copied as a subdirectory of the selected folder.
 
#* At a command or terminal prompt, navigate to the selected folder.
 
#* At a command or terminal prompt, navigate to the selected folder.
#* Clone the repository using the command:<br><code>[[/git clone/]] URL_TO_REPO</code>. See also: <code>git pull</code> and  <code>git fetch</code>
+
#* Clone the repository using the command:<br><code>[[git clone]] URL_TO_REPO</code>. See also: <code>[[git pull]]</code> and  <code>[[git fetch]]</code>
  
 
=== Create a local repository ===
 
=== Create a local repository ===
Line 14: Line 30:
 
#* Select a local folder to add to Git, or create a new folder if you are starting a new project.
 
#* Select a local folder to add to Git, or create a new folder if you are starting a new project.
 
#* At a command or terminal prompt, navigate to the selected folder.
 
#* At a command or terminal prompt, navigate to the selected folder.
#* Initialize the folder using the command:<br><code>git init</code>
+
#* Initialize the folder using the command:<br><code>[[git init]]</code>
  
=== Make Local Changes and Update remote Repositories ===
+
=== [[Make Local Changes and Update remote Repositories]] ===
Add local changes.
 
# Stage files.
 
#* Add files to the folder or modify existing files.
 
#* Add new and modified files to the git staging area using the command:<br><code>git add .</code><ref>http://man7.org/linux/man-pages/man1/git-add.1.html</ref> or <code>git add some_modified_file.txt</code> or <code>git add -A</code>
 
# Commit changes.
 
#* Commit changes into the local repository using the command:<br><code>git commit -m "&lt;some message&gt;"</code>
 
# Connect to a remote repository.
 
#* Connect to a remote repository using the command:<br><code>git remote add &lt;name&gt; &lt;url&gt;</code><ref>http://man7.org/linux/man-pages/man1/git-remote.1.html</ref>
 
# Push changes to a remote repository.
 
#* Push changes from your local repository to a remote repository using the command:<br><code>git push</code><ref>https://git-scm.com/docs/git-push</ref> or <code>git push origin master</code> or <code>git push -h origin master</code>
 
  
 
=== Retrieve Remote Changes ===
 
=== Retrieve Remote Changes ===
 
* Pull/get changes from a remote repository to have latest version of the code
 
* Pull/get changes from a remote repository to have latest version of the code
 
** Pull/get changes from a remote repository to your local repository using the command:
 
** Pull/get changes from a remote repository to your local repository using the command:
:::<code>[[/git pull/]]</code> or <code>git pull &lt;name&gt; &lt;branch&gt;</code>
+
:::<code>[[git pull]]</code> or <code>git pull &lt;name&gt; &lt;branch&gt;</code>
:::<code>git pull -v</code> (for more verbose output)
+
:::<code>[[git pull -v]]</code> (for more [[verbose]] output)
:::<code>[[/git fetch/]]</code>
+
:::<code>[[git fetch]]</code>
:::<code>gfind $1 -name ".git" | gsed -r 's|/[^/]+$||' | parallel "echo {}; git -C {} pull" </code> (git pull all your repos in parallel, MacOS version)
+
:::<code>[[gfind]] $1 -name "[[.git]]" | gsed -r 's|/[^/]+$||' | parallel "echo {}; git -C {} pull" </code> (git pull all your repos in parallel, MacOS version)
 
* Pull subdirectories:
 
* Pull subdirectories:
 
::<code>ls | parallel git -C {} pull</code> (assuming all sub-dirs are git repositories)<ref>https://stackoverflow.com/a/33557279</ref>
 
::<code>ls | parallel git -C {} pull</code> (assuming all sub-dirs are git repositories)<ref>https://stackoverflow.com/a/33557279</ref>
Line 41: Line 47:
  
 
=== Repository information ===
 
=== Repository information ===
* <code>git remote -v</code> or <code>git remote show origin</code> or <code>git config --get remote.origin.url</code><ref>https://stackoverflow.com/questions/4089430/how-can-i-determine-the-url-that-a-local-git-repository-was-originally-cloned-fr</ref>
+
* <code>[[git remote]] -v</code> or <code>git remote show origin</code> or <code>[[git config]] --get remote.origin.url</code><ref>https://stackoverflow.com/questions/4089430/how-can-i-determine-the-url-that-a-local-git-repository-was-originally-cloned-fr</ref>
  
=== Git log ===
+
=== [[git log]] ===
* <code>git log --oneline</code>
+
{{git log}}
* <code>git log --pretty=format:"%h - %an, %ar on %cd: %s"</code>
 
* Show modifications to a file:<code>git log --follow -p FILE_TO_SHOW</code><ref>https://stackoverflow.com/a/31306082</ref> or <code>git blame FILE_TO_SHOW</code>
 
* <code>git shortlog</code>
 
* List developers: <code>git shortlogs -sne</code><ref>https://stackoverflow.com/a/9597462</ref>
 
  
=== Git show ===
+
=== [[git show]] ===
* <code>git show 3c88ad72430</code>
+
* <code>[[git show]] 3c88ad72430</code>
  
 
=== Tags / Releases ===
 
=== Tags / Releases ===
* Show all tags in git log:<ref>https://stackoverflow.com/questions/4211604/show-all-tags-in-git-log</ref> <code>git log --no-walk --tags --pretty="%h %d %s" --decorate=full</code>
+
* Show all tags in git log:<ref>https://stackoverflow.com/questions/4211604/show-all-tags-in-git-log</ref> <code>[[git log]] --no-walk --tags --pretty="%h %d %s" --decorate=full</code>
* <code>git tag</code> (show releases)
+
* <code>[[git tag]]</code> (show releases)
* List tags with dates: <code>git log --tags --simplify-by-decoration --pretty="format:%ci %d"</code><ref>https://stackoverflow.com/a/13208822</ref>. Just can also add <code>taglog = log --tags --simplify-by-decoration --pretty='format:%ci %d'</code> (note the single-, NOT double-quotes) in the [alias] section of your [[/.gitconfig/]] file.
+
* List tags with dates: <code>git log --tags --simplify-by-decoration --pretty="format:%ci %d"</code><ref>https://stackoverflow.com/a/13208822</ref>. Just can also add <code>taglog = log --tags --simplify-by-decoration --pretty='format:%ci %d'</code> (note the single-, NOT double-quotes) in the [alias] section of your [[gitconfig]] file.
  
 
=== Miscelaneous ===
 
=== Miscelaneous ===
 
* <code>git log --decorate=full --simplify-by-decoration</code>
 
* <code>git log --decorate=full --simplify-by-decoration</code>
 
* Print lines matching a pattern:<code>git grep TEXT_TO_SEARCH</code>
 
* Print lines matching a pattern:<code>git grep TEXT_TO_SEARCH</code>
* <code>git merge</code><ref>https://dev.to/neshaz/how-to-use-git-merge-the-correctway-25pd</ref>
+
* <code>[[git merge]]</code><ref>https://dev.to/neshaz/how-to-use-git-merge-the-correctway-25pd</ref>
 +
* [[Move existing, uncommitted work to a new branch in git]]
 +
 
 +
== Tips and Tricks ==
 +
* To avoid using <code>--pager</code> in all <code>git log</code> commands, add the following line to your <code>~/.bash_profile</code> file:<ref>https://stackoverflow.com/a/7737071</ref><br><code>export GIT_PAGER=cat</code>
 +
 
 +
== Security ==
 +
* [[CVE-2022-24765]] windows and multi-user environments
 +
* [[gitrob]], [[TruffleHog]], [[gitleaks]]
 +
 
 +
== Related terms ==
 +
* <code>git update-git-for-windows</code>
 +
* [[Git Large File Storage (LFS)]]: <code>[[git lfs install]]</code>
 +
* <code>[[git-crypt]]</code>
 +
* <code>[[.git/config]]</code>
 +
* [[GitFlow]]
 +
* <code>[[git stash]]</code>
 +
* [[GitBook]]
 +
* <code>[[diffuse -m]]</code>
 +
 
 +
== Related software ==
 +
* [[GitHub]] ([[2008]])
 +
* [[GitLab]] ([[2011]])
 +
* [[Bitbucket]] (2008)
 +
 
 +
== Activities ==
 +
# [[Clone some git public repositories]]
 +
# Learn what is a merge or [[pull request]]: https://stackoverflow.com/questions/23076923/what-is-a-merge-request
 +
# Create your first website in [[Website Hosting]] using <code>git</code>
 +
# Read StackOverflow questions about Git: https://stackoverflow.com/questions/tagged/git?tab=Votes
 +
# [[Make Local Changes and Update remote Repositories]]
 +
# [[Create Git branch with current changes]]
 +
 
 +
== See also ==
 +
* {{git}}
 +
* {{git software}}
 +
* {{VCS}}
 +
* {{dev}}
 +
 
 +
 
 +
 
 +
{{CC license}} Source: wikiversity
 +
 
 +
[[Category: Computer programming]]
 +
[[Category:Concurrent Versions System]]

Latest revision as of 10:53, 20 April 2024

git (2005) is a distributed revision control software.

Activities[edit]

Git Installation[edit]

  1. Download Git from https://git-scm.com/downloads.
  2. Install Git. (MacOS: brew install git)
  3. apt install git or apt install git-all

Copy an existing remote repository[edit]

  1. Clone a remote repository.
    • Select a local folder to copy the repository into, or create a new folder if you prefer. The repository will be copied as a subdirectory of the selected folder.
    • At a command or terminal prompt, navigate to the selected folder.
    • Clone the repository using the command:
      git clone URL_TO_REPO. See also: git pull and git fetch

Create a local repository[edit]

  1. Initialize a folder for Git.
    • Select a local folder to add to Git, or create a new folder if you are starting a new project.
    • At a command or terminal prompt, navigate to the selected folder.
    • Initialize the folder using the command:
      git init

Make Local Changes and Update remote Repositories[edit]

Retrieve Remote Changes[edit]

  • Pull/get changes from a remote repository to have latest version of the code
    • Pull/get changes from a remote repository to your local repository using the command:
git pull or git pull <name> <branch>
git pull -v (for more verbose output)
git fetch
gfind $1 -name ".git" | gsed -r 's|/[^/]+$||' | parallel "echo {}; git -C {} pull" (git pull all your repos in parallel, MacOS version)
  • Pull subdirectories:
ls | parallel git -C {} pull (assuming all sub-dirs are git repositories)[1]
ls | parallel git -C {} fetch
-C <PATH> run as if git was started in <path> instead of the current working directory.

Repository information[edit]

git log[edit]

git log, git shortlog, git log --all

git show[edit]

Tags / Releases[edit]

  • Show all tags in git log:[3] git log --no-walk --tags --pretty="%h %d %s" --decorate=full
  • git tag (show releases)
  • List tags with dates: git log --tags --simplify-by-decoration --pretty="format:%ci %d"[4]. Just can also add taglog = log --tags --simplify-by-decoration --pretty='format:%ci %d' (note the single-, NOT double-quotes) in the [alias] section of your gitconfig file.

Miscelaneous[edit]

Tips and Tricks[edit]

  • To avoid using --pager in all git log commands, add the following line to your ~/.bash_profile file:[6]
    export GIT_PAGER=cat

Security[edit]

Related terms[edit]

Related software[edit]

Activities[edit]

  1. Clone some git public repositories
  2. Learn what is a merge or pull request: https://stackoverflow.com/questions/23076923/what-is-a-merge-request
  3. Create your first website in Website Hosting using git
  4. Read StackOverflow questions about Git: https://stackoverflow.com/questions/tagged/git?tab=Votes
  5. Make Local Changes and Update remote Repositories
  6. Create Git branch with current changes

See also[edit]


Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Source: wikiversity

Advertising: