Last active
March 14, 2018 23:52
-
-
Save davidnvq/6ea412204f69fe19601a75ddec7ad5ad to your computer and use it in GitHub Desktop.
Git guideline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## <0> Set-up environment | |
git config --global user.email "[email protected]" | |
git config --global user.name "Your Name" | |
# Cache the password | |
# https://help.github.com/articles/caching-your-github-password-in-git/#platform-linux | |
git config --global credential.helper 'cache --timeout=3600000' | |
# on Mac | |
git config --global credential.helper osxkeychain | |
# on Linux | |
$ git config --global credential.helper store | |
$ git push http://example.com/repo.git | |
Username: <type your username> | |
Password: <type your password> | |
# Set the user in .git/config | |
#Change: | |
url = "https://github.com/WEMP/project-slideshow.git" | |
#to: | |
url = "https://*username*@github.com/WEMP/project-slideshow.git" | |
## <A> BASIC GIT FLOW | |
# 1. Create a project | |
git init | |
# 2. Check the status | |
git status | |
# 3. Git flow | |
# A git project can be thought of having 3 parts: | |
# - A working directory: where we'll be doing all the work: creating, editing, deleting and organizing files. | |
# - A staging area: where we'll list changes we make to the working directory | |
# - A repository: where git permanently storees those changes as different versions of project. | |
# 4. Start tracking: we add the files to the staging area. | |
git add filename | |
git add filename1 filename2 | |
git add . | |
#5. Compare the difference | |
git diff filename | |
git diff . | |
#6. Store the changes to the repository | |
git commit -m "message here" | |
#7. Refer to the earlier version of the project | |
git log | |
## <B> HOW TO BACKTRACK | |
#1. Head commit: The current (most recent) commit is HEAD. To see the current commit, enter: | |
git show HEAD | |
#2. Restore some files to the last (HEAD) commit. | |
git checkout HEAD filename | |
#3. Restore to the specific commit | |
git reset --hard commit_SHA | |
## <C> BRANCHING | |
#1. Show the current branch | |
git branch | |
#2. Create a new branch | |
git branch branch_name | |
#3. Switch the branch | |
git checkout branch_name | |
#4. Merge the branch into master with: | |
git checkout master #then | |
git merge branch_name | |
#5. delete branch | |
git branch -d branch_name | |
## <D> GIT TEAMWORK | |
# We can manage the project with other members: | |
# - Keep track and review of each other's work | |
# - Access to a definitive project version | |
# A remote is a shared repository allowing multiple collaborators to work on the same | |
# Git project from different locations. | |
#1. Clone it | |
git clone remote_location | |
#2. See a list of a git project's remotes | |
git remote -v | |
#3. Update the changes to the most up-to-date | |
git fetch | |
#4. git merge | |
# The remote work is fetched to our local copy of git project. | |
# Those commits are on the origin/master branch | |
# Our local master has not been updated yet, | |
# so we can't view or make changes to any of the work she has added | |
git merge origin/master #(merge "origin/master" branch to current local branch) | |
#5. Push our branch up to the remote for review | |
git push origin our_branch_name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment