Ad

Sunday, June 17, 2018

Git and Github basics

$git config --global color.ui true
$git remote -v
$heroku run rake assets:precompile

git add <list o files>
git add --all
git add *.txt
git add directory/*.txt
git add directory/
git add "*.txt" (add all txt files of the entire project)

#compare diff between local and remote
git diff
# compare what's in the staged repo (after $add .) versus unstaged
git diff --staged
#unset changes in stage
git reset <filename>

## git head is the last commit on the current branch

#restoring file to the previous state
git checkout -- filename
git checkout -- fileone filetwo

# add and commit at the same time
# caveat does not add new files, still need to add it separately
git commit -a -m "comments here"

# undoing a commit
# move to the commit one before the current head (previous head)
# changes to go back to staging area
git reset --soft HEAD^
# or
git commit --amend -m "adding to the previous commit and also modify the message"
# or
#completely remove the previous commit
$git reset --hard HEAD^
# or completely remove the previous two commits
$git reset --hard HEAD^^


#sharing git
#dealing with remote repository
# git does not handle access control, it is usually is handled by GitHub or BitBucket

## check remote
$git remote -v
herokugit@heroku.com:whispering-springs-5104.git (fetch)
 herokugit@heroku.com:whispering-springs-5104.git (push)
 originhttps://github.com/theoptips/taskcloud.git (fetch)
 originhttps://github.com/theoptips/taskcloud.git (push)

 ##managing remotes
 $git remote add <name> <address>
 $git remote rm <name>

 ## heroku create will automatically add a remote called "heroku"
 git push <remote name> <branch name>
 git push heroku master

 ## branching
 $git checkout master
 $git merge <branchname>
 # git fast forward



## branching
$git checkout master
$git merge <branchname>
# git fast forward
# delete a git branch
$git branch -d <branchname>
# create a branch and checkout
$git checkout -b <branchname>

## always git pull from remote to ensure that there are no new changes
## if branch and master are at different timelines, i.e. not all new changes are committed
## in the branch that is about to be merged, then git will open an VI to view the changes
## git merge recursively and also create a node in the log about the merge

## merge commit
## if remote is ahead
## then have to pull
## which merge origin/master, the remote, with the local master
## then need to git push to add the new changes


## scenario: same file, conflicts
## git pull, syncs repo, pulls down all the changes, and try to merge
## discover a conflict
## need to edit the file, diff, edit manually to fix it,
## git commit -a
## vi editor will give a detailed message


#list all remote branches
$git branch -r
# help check branch histories versions
$git remote show <remotename>
#delete a remote branch ONLY
$git push <remotename> :<remote branch name>
$git branch -d <localbranchname>
# to delete LOCAL branch forcefully
$git branch -D <localbranchname>

No comments:

Post a Comment

Codecademy - Machine Learning Fundamentals - Syllabus

Upgrade your skills with Codecademy's Pro Intensive, Machine Learning Fundamentals. Each unit will cover conceptual and syntax lessons ...