Git

From wikieduonline
Jump to navigation Jump to search

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]

See also[edit]

Advertising: