Introduction To Version Control With Git
- 1. Version Control
- 2. Git
- 3. Git Basics
- 4. Hosted Git Basics
Version control is the practice of tracking changes to any kind of data like code, documents, or artwork. Version control systems provide a complete change history and allow versions of the same data to be manipulated separately.
The entire change history is kept in git repositories. Git repositories can be manipulated on your personal computer or shared with others on websites like GitLab.
Setting up repository, git init. Ensure git is installed. How to install Git.
The repository is .git. To initialize the repository do:
Changes must be staged and committed in the same directory as the repository to be tracked by git. The contents of the next commit are determined by what changes are staged. git commit creates a new snapshot of the staged changed.
The .git file stages changes. The next commit is described by the staged changes. git add stages the latest changes of whatever file it is targeting. s
git add SuperImportantPaper.txt
git add .
git commit appends a new snapshot, specified by the staged changes, to the git repository.
To track information about the commit author, git needs and email and name.
git config user.email "AllFather@Highlands.Above" git config user.name "YourAllFather"
You need to specify the email and name for commits to the repository, otherwise the following error occurs when running git commit.
$ git commit Author identity unknown *** Please tell me who you are. Run git config --global user.email "firstname.lastname@example.org" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address
Enter a commit message with the default text editor set for git commit.
A branch is a independent series of commits. Each repository begins with a main /master branch. Branching can be used to keep a separate series of commits from the main to facilitate multiple people working on the same set of data.
$ git branch -v # A fancy way to see the branches with git log. Press q to quit $ alias.lgb=log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches $ git lgb
git branch starts a separate branch from the current branch. Changes to this branch won’t be tracked in other branches.
$ git branch differentBranch
$ git branch -v
git checkout switches from the current branch to a different branch.
$ git checkout differentBranch
GitHub and GitLab are online platforms used to collaborate and **
store repositories. ** To edit a repository stored on GitHub or GitLab it must be cloned. GitHub and GitLab provide forking capabilities which are similar to branching.
git clone allows editing of a repository on GitLab. git clone downloads the repository from GitLab into the current working directory.
To clone a repository navigate to it’s page on GitLab and copy it’s clone link:
$ git clone email@example.com:nbc170001/docs-science-support-meeting-minutes.git
git push allows users to make changes to the repository stored on GitLab. git push uploads the local snapshot of the repository to the online repository.
$ git push origin yourBranch
Forking allows users to make their own copy of another person’s repository on GitLab which they can freely edit.
To fork a repository navigate to the repository on GitLab and select fork:
To make changes to your fork, clone the repository and push your changes.
Pulling is how changes are made to a GitLab repository based on it’s fork.
To submit a pull request navigate to the original repository’s GitLab page and do compare and pull request button: