Git Memo

This is the current content sections of the page: Git Basics + Atom tips


Git Basics

Usage

The order of operations is:
Make your change.
git add - this stages your changes for committing
git commit - this commits your staged changes locally
git push - this pushes your committed changes to a remote
If you push without committing, nothing gets pushed. If you commit without adding, nothing gets committed. If you add without committing, nothing at all happens, git merely remembers that the changes you added should be considered for the following commit.
The message you're seeing (your branch is ahead by 1 commit) means that your local repository has one commit that hasn't been pushed yet.
In other words: add and commit are local operations, push, pull and fetch are operations that interact with a remote.

TO RESET CHANGES

git reset --hard HEAD~
You may want to check to make absolutely sure you want this (git log), because you'll loose all changes.
A safer alternative is to run:
git reset --soft HEAD~ # reset to the last commit
git stash # stash all the changes in the working tree
git push # push changes
git stash pop # get your changes back
Or:
git pull to download the original repo in its remote current state.

Git Basic Commands

Quick setup — if you’ve done this kind of thing before: Set up in Desktop or HTTPS, SSH. We recommend every repository include a README, LICENSE, and .gitignore. First configuration:
git config --global core.editor "vim" git config --global credential.helper 'cache --timeout=360000' git config --global user.name GithubUserName git config --global user.email AccountmailAddress Initiate a Repository with Command Line echo "#REPOSITORY_NAME" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/GithubUserName/REPOSITORY_NAME.git git push -u origin master Or push an existing repository from the command line:
git remote add origin https://github.com/GithubUserName/REPOSITORY_NAME.git git push -u origin master Or import code from another repository. You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
Github example from address https://github.com/ithubUserName/REPOSITORY_NAME:
git config --global credential.helper 'cache --timeout=3600' git rm -r --cached REPO_NAME && git commit -m 'Removed old directory "REPO_NAME" ' && git push origin master Git: clean up folders local and remote. From the Repository root directory, run:
git filter-branch -f --tree-filter 'rm -rf package_dir/sub_package_dir' HEAD Example:
git filter-branch -f --tree-filter 'rm -rf exercices/exercice-php' HEAD -f is to force the command line in case of multiple deletions which require to force the backup branch three to be updated more than once.
Then push changes with --force option:
git push --force

Git VIM Editor + Basic git config --global

git config --global core.editor "vim" git config --global credential.helper 'cache --timeout=3600' git config --global user.name GithubUserName git config --global user.email AccountmailAddress Useful Resources and Links
git-scm.com/book/fr/v2/Utilitaires-Git-Stockage-des-identifiants git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup

Atom Tips & Tricks

Files Treeview:
Git status: orange for modified, green for new, red for deleted.

Create a repository from the command line

touch README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/$USERNAME/$REPO.git git push -u origin master ## Push an existing repository from the command line git remote add origin https://github.com/$USERNAME/$REPO.git git push -u origin master