Version Control/Git
(Redirected from Git)
Git is a distributed revision control software used by many open source projects. This learning resource is meant to help students learn to use it so that they can collaborate with other participants on software projects at Wikiversity.

ReadingsEdit
MultimediaEdit
TermsEdit
- Version control: The act of tracking the changes made by one or more users on a set of files
- Remote repository: A directory of files tracked by a version control software on a server, usually accessed via the internet
- Clone: To make a local copy of a remote repository
- Branch: A set of deviations from a particular state of the repository
- Merge: The act of combining two branches into a single one
- Pull: To update a local repository with the latest changes from a remote repository
- Push: To update a remote repository with the latest changes from a local repository
ActivitiesEdit
Git InstallationEdit
- Windows: Download and install Git from https://git-scm.com/downloads.
- MacOS:
brew install git
- Debian-based Linux:
apt-get install git
- Arch-based Linux:
pacman -S git
Copy an existing remote repositoryEdit
- 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
andgit fetch
Create a local repositoryEdit
- 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 RepositoriesEdit
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:
git add .
[1] orgit add some_modified_file.txt
orgit add -A
- Commit changes.
- Commit changes into the local repository using the command:
git commit -m "<some message>"
- Commit changes into the local repository using the command:
- Connect to a remote repository.
- Connect to a remote repository using the command:
git remote add <name> <url>
[2]
- Connect to a remote repository using the command:
- Push changes to a remote repository.
- Push changes from your local repository to a remote repository using the command:
git push
[3] orgit push origin master
orgit push -h origin master
- Push changes from your local repository to a remote repository using the command:
Retrieve Remote ChangesEdit
- 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
orgit 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 informationEdit
git remote -v
orgit remote show origin
orgit config --get remote.origin.url
[5]
Git logEdit
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] orgit blame FILE_TO_SHOW
git shortlog
- List developers:
git shortlogs -sne
[7]
Git showEdit
git show 3c88ad72430
Tags / ReleasesEdit
- 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 addtaglog = log --tags --simplify-by-decoration --pretty='format:%ci %d'
(note the single-, NOT double-quotes) in the [alias] section of your .gitconfig file.
MiscelaneousEdit
git log --decorate=full --simplify-by-decoration
- Print lines matching a pattern:
git grep TEXT_TO_SEARCH
git merge
[10]
Tips and TricksEdit
- To avoid using
--pager
in allgit log
commands, add the following line to your~/.bash_profile
file:[11]export GIT_PAGER=cat
ActivitiesEdit
- Clone some 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 GitHub/Website Hosting using git
- Read StackOverflow questions about Git: https://stackoverflow.com/questions/tagged/git?tab=Votes
Readings and learning resourcesEdit
WikipediaEdit
- Git
- Version control
- Tig (software)
- Comparison of source-code-hosting facilities
- Collaborative development environment
- Comparison of version-control software
- Comparison of source-code-hosting facilities
- List of version-control software
- TortoiseGit
- Category:Git (software)
- Fork and pull model
- Gitea
- GitHub
- Timeline of GitHub
- Collaborative innovation network
- Collaborative intelligence
- Commons-based peer production
- DevOps
- GitLab
- Gitee
- Magit
- Virtual File System for Git
ExternalEdit
- Pro Git – a book written by Scott Chacon and Ben Straub
- Git Documentation on git-scm.com
- GitHub: Git Handbook
- GitHub: Git Tutorial
See AlsoEdit
ReferencesEdit
- ↑ http://man7.org/linux/man-pages/man1/git-add.1.html
- ↑ http://man7.org/linux/man-pages/man1/git-remote.1.html
- ↑ https://git-scm.com/docs/git-push
- ↑ https://stackoverflow.com/a/33557279
- ↑ https://stackoverflow.com/questions/4089430/how-can-i-determine-the-url-that-a-local-git-repository-was-originally-cloned-fr
- ↑ https://stackoverflow.com/a/31306082
- ↑ https://stackoverflow.com/a/9597462
- ↑ https://stackoverflow.com/questions/4211604/show-all-tags-in-git-log
- ↑ https://stackoverflow.com/a/13208822
- ↑ https://dev.to/neshaz/how-to-use-git-merge-the-correctway-25pd
- ↑ https://stackoverflow.com/a/7737071