Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 1.81 KB

basics.org

File metadata and controls

63 lines (49 loc) · 1.81 KB

GIT basics

Local git

Create a repo

Use git init [name of repo] to initialize a git repository

Build commit in staging area

git add [filename] It is possible to pass directories as args. No args adds everything.

Commit changes

Stores the changes of one or more files.

Contents:

  • Message
  • Author
  • Unique reference SHA-1
  • Parent reference
  • Date
  • File diffs

git commit -m message

Remote git

Git is a distributed version control system, so you can use it offine and locally. But it is really useful to share our work with others.

Adding a remote repo

You can add a remote repo, in this case hosted by Github.

git remote add origin git remote --verbose to check the remote has been added. It lists a fetch and push remote, it is normally the same. If you have a single remote, it is called origin.

Push changes to a remote repo

Send commits in a local repo to a remote. Made through HTTP or SSH protocols. Only differences are sent.

git push --set-upstream origin master The first time. Also git push -u origin master It is a healthy option to make sure the local master branch tracks the origin remote’s branch master. A tracking branch is the default push or fetch location for a branch The next time you can run: git push origin master

Cloning a remote

Clone
Create a new local repo from an existing remote. It’s a complete copy including all metadata
  • git clone [remote location]

Fetch changes without merging

  • git fetch to download the new commits but skip the merge step, in contrast to git pull

Push or fetch: It’s recommended git fetch. You can fetch regularly in the background and only include changes in the branch when it’s convenient and using the most convenient method.

Tips & tricks

  • command –help