From XPUB & Lens-Based wiki
Revision as of 13:04, 29 September 2019 by Andre Castro (talk | contribs) (recipe on how to clone n push to gitea remotes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

install Git


Git is installed when you install Xcode

to check if it is installed run in the command line:

git --version

If it responds with a version number, Git is installed

Start Git: init

To start using Git, you need:

  • a dedicated folder for you project, where all files and sub-folders of the project live
  • navigate with the command line to that folder: cd path/to/folder
  • initialize Git: git init

The last step with create a hidden .git/ folder where all the Git data will be stored.

3 Git moments


For local (in your computer) Git operations, there are 3 main moments:

  • working: editing files
  • stage: adding (tracking) files to git
  • commit: span-shooting the changes performed on files


Staging refers to the action of making files ready for commit.

  • git add when run for the 1st time on file or folder, it ask Git to start tracking it
    • on a file that is being tracked, but has since changed, it include those changes to be commited
    • There might be files you might not want to track and therefore you don't add them
  • git status overview or staged moment:
    • displays tracked and untracked files

Trick: If you wanna stage from files which Git is tracking run: git add -u


A commit is version of your project. When you complete some part of the work, you commit!

  • git commit -m "message about what happened in that commit" creates a version or commit of your project. A accompanying message describes what happen in that commit.
  • git log show the history of commits, where each commit is shows an author, date, message and hash (a long string of letter and numbers that identifies the commit)

Undoing things


Unstage, means bring added changes out or the stage moment. In other words, before commiting, the changes you made to a file, then git add that.file, can be undone by running:

git reset HEAD

Warning: those changes will be lost!

checkout a specific commit

The state of files in a specific commit can be checked out using:

git checkout commit-hash

This command will detach the HEAD (like the reading head of a K7) from the latest commit. In other words, it will let you go back in time to a previous commit.

To keep it simple, you can't do much there, but look around, copy content from files and save them in new (untracked) files.

When you are done, you can return the head to the latest commit by running

git checkout master


Reverts the head to a previous commit: git revert commit-hash

But instead of erasing history, creates a new commit


Git Cheatsheet

Git home

blog on Github Terms of Services

Remotes / collaboration

Git facilitates the coordination of contributions from different collaborators in a project.

Each contributor has a local repository, that is a 'clone' of the remote repository.

The remote repository acts as the central node from which all the users will receive - pull - and send - push contributions.

git commands: Trees, Branches, and Blobs

git init
git add *
git commit -m 'hello git'

init, clone

git init
git clone git://...

status, add, diff

tracked/untracked "staged"

file status lifecycle, p. 20 gitbok

git status

Add a file called ".gitignore" to ignore "temporary" or other files you don't want to track.


git diff

Shows changes to unstaged files only

git diff --cached

Show what you've staged so far


git commit -m 'added new quote'
git commit -a -m 'edited links'

Stages every file (that's being tracked) -- ie "auto add"

git commit --amend

Add forgotten changes to last commit.


git rm readme.txt
git rm --cached readme.txt

Remove from the stage, but not the file! (untrack)

git mv

(technically git "sees" these movements already, same as mv, remove, add: but the command is there for convenience)


git log
git log -p -2
git log --stat
git log --pretty=oneline
git log --graph


git remote
git remote -v
git add remote remote-name URL

Where remote-name is whatever you want it to be called, and the URL is a remote git URL.

git remote show origin
git fetch remote-name


pull = fetch + merge


git push [remote-name] [branch-name]
git push origin master


Show SMW ?!

<!?> Find/link workflow article for git + web



Add to .bashrc:

source ~/.git-completion.bash


cp git-completion.bash /etc/bash_completion.d/


cp git-completion.bash /opt/local/etc/bash_completion.d/



git checkout -b iss53

create + checkout a branch, short for:

git branch iss53
git checkout iss53
git checkout master
git checkout -b fix
git commit -a -m 'fixed something'
git checkout master
git merge fix
git branch -d fix

"Fast-forward" reflects that the changes were "upstream" of the current working state.


Generally, you want to commit all your changes before switching branches (checkout)

If we each write to master -- lots of conflicts? Contrast with creating branch for each person ?!


Cloning from

Pushing changes to

If you

  • are the owner, collaborator, or belong to one of the XPUB teams with rights over over a repository,
  • your ssh public keys is in your profile settings

you can push your commits onto the existing repository in


git clone ssh://

make your changes


add the changes done to tracked files

git add -u  

if you create a new file, add it

git add newfilename

write a commit message

git commit -m "the changes i made in this comit"

push your commit(s) to

git push origin master