Difference between revisions of "Git"

From wikieduonline
Jump to navigation Jump to search
Line 62: Line 62:
 
=== 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.
  

Revision as of 07:58, 26 December 2019

Git is a distributed revision control software.


Activities

Git Installation

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

Copy an existing remote repository

  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

  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

Add local changes.

  1. Stage files.
    • Add files to the folder or modify existing files.
    • Add new and modified files to the git staging area using the command:
      git add .[1] or git add some_modified_file.txt or git add -A
  2. Commit changes.
    • Commit changes into the local repository using the command:
      git commit -m "<some message>"
  3. Connect to a remote repository.
    • Connect to a remote repository using the command:
      git remote add <name> <url>[2]
  4. Push changes to a remote repository.
    • Push changes from your local repository to a remote repository using the command:
      git push[3] or git push origin master or git push -h origin master

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 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)[4]
ls | parallel git -C {} fetch
-C <PATH> run as if git was started in <path> instead of the current working directory.

Repository information

  • git remote -v or git remote show origin or git config --get remote.origin.url[5]

Git log

  • git log
  • git log -p
  • git log --all
  • git log --oneline
  • git log --pretty=format:"%h - %an, %ar on %cd: %s"
  • Show modifications to a file:git log --follow -p FILE_TO_SHOW[6] or git blame FILE_TO_SHOW
  • git shortlog
  • List developers: git shortlogs -sne[7]

Git show

  • git show 3c88ad72430

Tags / Releases

  • Show all tags in git log:[8] 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"[9]. 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

  • git log --decorate=full --simplify-by-decoration
  • Print lines matching a pattern:git grep TEXT_TO_SEARCH
  • git merge[10]

Tips and Tricks

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

Activities

  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 GitHub/Website Hosting using git
  4. Read StackOverflow questions about Git: https://stackoverflow.com/questions/tagged/git?tab=Votes

See also


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: https://en.wikiversity.org/wiki/Version_Control/Git

Advertising: