Blue Flower

Login & create repository

https://github.com/new

(don't create README if you want to add existing project)

Staging & un-staging

git add helloworld/src/app/child2/child2.component.html

git reset HEAD helloworld/src/app/child2/child2.component.html

Create files and push it to test repository

git init

git add README.md

git commit -m "first commit"

git remote add origin https://github.com/<<gitname>>/projectname.git

git push -u origin master


To get all latest from server to local

git pull

To create a new branch

git branch <<new branch name>>

git checkout <<new branch name>>

or shorthand

git checkout -b <<new branch name>>

To switch to other branch

git checkout <<branch name>>

git checkout hotfix

To merge branch

git checkout master (where do we want to merge)

git merge hotfix (which branch want to merge)

Note: If same file edited in both branch then conflict occurs and it has to be removed. This can be can done in Visual Studio Code (accept branc1 changes, or branch2 changes or both)

 After merge again stage and commit

git push -u origin master

To delete the branch

After merging the hotfix branch then it can be deleted

git branch -d hotfix

Make changes in another open DEV branch

git checkout dev

<<make changes>>

git commit -m "2nd time commit from DEV branch"

git push -u origin dev

Again merge DEV branch into MASTER

git checkout master

git merge dev

[if conflicts happens then again resolve it manually or using visual studio code]

git add <<file name resolved>>

git add . (if more file resolved)

git commit -m "merged dev to master"

git push -u origin master

Delete DEV branch if no longer required

git branch -d DEV

Ignore tracking changes 

git update-index –assume-unchanged testfile.txt

Undo ignored files and track back its changes 

git update-index –no-assume-unchanged testfile.txt


Few more branch related commands

git branch (list all branches with * denoting that HEADS point to)

git branch -v (to see last commit on each branch)

git branch --merged (which branches are merged into the branch we are currently on)

git branch --no-merged (branches that are not merged in yet)

git branch -d <<branchname>>

(if the branch is not merged then git won't allow to delete in that case use git branch -D <<branchname>>)

Stashing and Cleaning

Its important to keep sync current branch before switch over other branch to work

If you don't want to commit dirty changes until now then we can park it using stashing and later reapply to any branch we want

git stash

(after stashing git status => nothing to commit, working directory clean)

git stash list (list out stored stashes)

git stash apply (apply the last stored stashing into current branch)

git stash apply --index (to restage the changes after stashing)

git stash drop (to drop the stashing)

 

Undoing changes

git checkout to move around and review the commit history

git revert is the best tool for undoing shared public changes

git reset is best used for undoing local private changes

 

Cleaning your Working Directory

git reset (unstage all uncommitted local changes)
git clean (if we want to discard all changes then )

Ignore local changes

If we don't care about any local changes (including untracked or generated files or subrepositories which just happen to be here) and just want a copy from the repo:

git reset --hard HEAD git clean -xffd git pull

Again, this will remove any changes you've made locally so use carefully.

So use rm -Rf to see affected files in prior apply actual clean command

Pull new changes by other team members

$ git pull https://github.com/<<gitname>>/projectname.git

You have no rights to post comments