Git - A distributed version-control system
Home > General > Git
Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows. Wikipedia
Contents
- Github
- Obtaining a Git Client
- Configuring your Git Client
- General Git Usage
- Additional Resources
Github
Creating an Account
- Visit https://github.com/join
- Specify a username, enter your email address and a password and follow the steps
- Verify your email address
Creating a Repository
- You’ll need to have an account setup before proceeding.
- See the most recent page at https://help.github.com/en/articles/create-a-repo
Obtaining a Git client
In order to interface with github effectively you’ll need a git client. From the git client you’ll be able to “push” code changes from your local folders up to github for safe keeping and version control.
Windows
- Visit https://git-scm.com/download/win
- Download the git client and run the executable
- Follow all on-screen instructions, the default options are usually the best.
- You’re all set! There should have “Git Bash” available in your start menu.
Linux
- For Debian based distributions like Ubuntu run the following commands from your terminal:
sudo apt update
sudo apt install git
- For RedHat based distributions like Fedora run the following commands from your terminal.
dnf -y update
dnf -y install git
Mac
- Visit https://git-scm.com/download/mac
- Download the git client and run the executable
- Follow all on-screen instructions, the default options are usually the best.
Configuring your Git Client
Your git client will need to be configured correctly before you can push changes up to your repository. Execute the following commands from your terminal/git client to set your name and email address. Replace the sample information with your own.
git config --global user.name "sampleuser"
git config --global user.email "sampleuser@example.com"
To see these changes execute
Yout should see something similar to the following:
[root@host ~]# git config --list
user.name=sampleuser
user.email=sampleuser@example.com
General Git Usage
Initializing a Directory
- Ensure you’ve created a repository using the steps here
- Open git bash (terminal in linux)
- Ensure the directory hasn’t already been initialized
- If you recieve “fatal: Not a git repository (or any of the parent directories): .git” the repository is already being tracked.
- Otherwise, execute the following
git remote add origin [web address of github repository]
git add -A
git commit -m "first commit"
git push origin master
Pushing Changes up to a remote repository
- Open git bash (terminal in linux)
- Change your current working directory to your local repository
- To stage a single file you’ve changed to be pushed up to your remote repository execute
- To stage all files you’ve changed execute
- To commit the tracked changes and prepare them to be pushed to a remote repository, execute the following with your choice of message (-m)
git commit -m "Add files"
- Push your changes to the remote repository
If you’ve created a separate branch for your code, replace master with your branch name.
Using .gitignore
To ignore certain files in your local repository and prevent your git client from seeing them take the following steps:
- Add a .gitignore file to the root of your local repository
- Add filenames to be ignored
- Wildcard characters such as ‘*’ are acceptable
See https://git-scm.com/docs/gitignore for more information.
Reseting all changes since your last commit
To revert all local changes in your local repository execute:
Additional Resources
References
This page is part of a collection of pages on various topics of Computational Neuroscience. Please direct questions and suggestions to the author Tyler Banks at tbanks@mail.missouri.edu.