Skip to content

keoughkath/git-primer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 

Repository files navigation

git-primer (cheatsheet, docs)

Git is a technology that allows you to efficiently save and manage multiple versions of the code for a project. The collection of different versions is called a repository, and multiple users can each have their own repository for the same project. Each repository can serve as a source from which other repositories can pull and a destination to which other repositories can push -- it's distributed. Many sites host git repositories and add a web-based interface, such as GitHub, Bitbucket and GitLab. This primer is focused on using git from the command line, but some people use a GUI, such as GH Desktop or EGit.

Get Started (First Time)

git config --global user.name "Jay Doe"
git config --global user.email [email protected]

Clone a Repo (GitHub)

Sign into your GitHub account and visit the desired repository, e.g., git-primer. Click the "Fork" button in the upper right, and when your fork is created, click the green "Clone or download" button to copy the URL, e.g., https://github.com/gladstone-institutes/git-primer.git, to your clipboard. Then open your terminal to create a local version of the repository from the command line (your copied URL should have your GitHub username instead of gladstone-institutes):

git clone https://github.com/gladstone-institutes/git-primer.git
cd git-primer

Work with Git

Check status.

git status

Create a new branch named my-feature and push it to GitHub. It's a good idea to keep your active development in a separate branch from master so that master is always in the last known good state. For more information, see our git workflows document.

git checkout -b my-feature
git push origin my-feature

Make some changes.

mkdir my-dir
touch my-dir/my-file.txt

Add all files to be tracked.

git add .

Add only certain files to be tracked.

git add file.txt

Commit your work (do this often).

git add ./my-dir/my-file.txt
git commit ./my-dir/my-file.txt -m "create my file"

Sync with GitHub (remote).

git pull origin my-feature

If someone else was working on the branch, you may need to merge their work with yours. Git gives you many different options for doing this, but most often, you can just use this procedure:

git mergetool

Select your preferred tool and complete the merge. If you select Opendiff, just use the GUI and save your merge. If you select Vim, follow these instructions:

----------------------------------------
|            |            |            |
|   LOCAL    |    BASE    |   REMOTE   |
|            |            |            |
----------------------------------------
|                                      |
|                 MERGED               |
|                                      |
----------------------------------------

Use ]c to jump to the next difference. Then get version from one of the three options above:

  • :diffget LO
  • :diffget BA
  • :diffget RE

When complete, save and exit with :wqa.

Commit your merge (if you needed to merge) and push to GitHub:

git push origin my-feature

When your changes are production ready, merge your work into your local master branch.

git checkout master
git diff my-feature # optional
git merge my-feature

Push to GitHub (remote).

git pull origin master
git push origin master

Delete feature branch both locally and at GitHub.

git branch -d my-feature
git push origin -d my-feature

About

Quick start for git

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published