DEV Community

loading...
Cover image for Minimalist git

Minimalist git

roramigator profile image Morado Updated on ・2 min read

Setup

Download git.
Use: git <command> [<args>]

Creating

Executing git init inside the project folder will create a new repository.

Cloning

A copy of any repository can be created using git clone /path/to/repo for local and git clone username@host:/path/to/repo for remote.

How (g)it works

The working directoryproject/— holds all the files; to avoid complications, the staging areaproject/.git/index— could be seen as where the modified files are stored; after changes are commited, the repository or HEADproject/.git/objects— will be updated and ready to push.

workflow

Add & Commit

When a file is modified git add <filename> will place a file into the staging area, git add . can be used to add all files. This gets the modified files ready to commit.
To actually commit the changes git commit -m "Message" is to be used, now the file is commited to the HEAD but not to the remote repository yet.

Pushing

git push origin <branch> will send the changes from the HEAD to the remote repository.
In order to push, the repository must be connected to a remote server, git remote add origin <server> will do the trick.

Branching

The master branch is the "default" branch when a repository is created. Other branches are use to develop features isolated from each other; Create-Develop-Merge.

branches

To create and move to a branch named develop: git checkout -b develop; to switch back to master: git checkout master; delete the branch: git branch -d develop; push the branch to remote repository: git push origin <branch>.

Update & Merge

To update the local repository, git pull will fetch and merge remote changes; To merge a branch into the active branch: git merge <branch>.
When pulling/merging git tries to auto-merge changes, sometimes possible conflicts arise, in such cases a manual editing of the files in conflict need to be done; after changes are made, index the files using git add <filename>.

Links

A visual git reference
Workflows

Discussion

pic
Editor guide