Saturday, June 30, 2018

Git Helper

Git Steps

Testing : $python -m unittest discover

Initialize the folder with Git

$ Git init

Clone/Copy the folder from git to local folder

$ Git Clone git@github.com:usf-614/user-name.git



Git branching

To see current branches
$ git branch
*master

To create new branch called dev
$ git branch dev

To change from master to dev
$ git checkout dev

Useful at this stage
$ git stash -->  if pending changes are present-used to save in unnamed space temporarily
$ git stash pop --> to bring back the stashed contents back

Checking status
$ git status

How branching works:
Currently master branch with 10 files. Create clean-up branch with same 10 files. Git checkout the clean-up branch. Delete 4 unnecessary files from the branch. Once task is completed, git checkout master. Master still has 10 original files while branch has only 6 files. Now to sync the master with the branch, while on master, run git merge clean-up; the master should now have the same 6 files in branch. Once done, clean up the branch itself by : git branch -d clean-up

After all said and done: git push

After editing the local file in editors like Pycharm, upload it back to Git.

$ git add prelab.py
$ git commit -m 'describe the change'
$ git push origin dev
$ git commit --amend -m "an updated commit message" --> correct the message
$ git add "*.txt"

History
git log


Remote Repositories

 git remote add origin https://github.com/try-git/try_git.git

git push -u origin master // -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do.

git pull origin master

git diff HEAD  // check the difference in origin from our recent commit HEAD

git add newfile.ext. // new file staged

git diff --staged  // check new staged files.

If you don't want the file to be staged, unstage it by:
git reset newfile.ext


To revert to a point where a particular file was committed eg. pointGood.ext:
git checkout -- pointGood.ext



Pull unit test from Master to dev

$ git fetch
$ git checkout dev
$ git stash --> if changes pending
$ git checkout master
$ git pull
$ git log
$ git checkout dev
$ git merge master
~
~
~
~
~
~:wq
$ git stash pop
$ git log --> notice last event was a merge


Commands in an empty repo

Git global setup
git config --global user.name "Suraj Joshi"
git config --global user.email "suraj.joshi@bmrn.com"



Create a new repository
git clone git@git.abc.com:sadf/MainNovember17.git
cd MainNovember17
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master



Existing folder
cd existing_folder
git init
git remote add origin git@git.abc.com:sfaf/MainNovember17.git
git add .
git commit -m "Initial commit"
git push -u origin master



Existing Git repository
cd existing_repo
git remote add origin git@git.abc.com:sdaf/MainNovember17.git
git push -u origin --all

git push -u origin --tags

No comments: