GIT HUB quick guide

git architecture


 Staging area means files under tracking ready for commit. (will show in green text)

Download the git with gitbash

Right click and Open gitbash on any working directory.


Basic Commands:

git status

To check the status of pwd

git clone  url_from_git_hub_clone

It will download the project.

git init

create the git repository. .git folder will be created under pwd.

git add --a    or  git add .

will add all files in staging area. To ignore file and folder create touch .gitignore 

git commit -m "first commit"

It will commit all the staged file

git commit -a -m "Direct commit of tracked file without staging"

It will ignore any untracked new file in working directory and commit the tracked file.

(good to ignore out or bin folder created later after first track)

git rm --cached foldername

remove tracking of file or folder. Good for out or bin folder

git restore --staged filename

To remove from staged(green to red) but still tracking.

git checkout -- filename

Restore the changes as per last commit. You will lost current changes in working file.

git checkout -- f

Restore working directory with last commit.


Branching: Make new branch (i.e. your version of code):

git checkout -b branchname

Show branches

git branch

make the changes

git add .
git commit -m "changes in devbranch"

branch switching (Always switch branch after commit)
git checkout existingbranchname

It will switch branch to master.
git checkout master


To merge branch with master. Run following in master and commit.
git merge branchname

git branch --merged
git branch --no-merged
git branch -v

After merging branches can be deleted
git branch -d branchname

Deleting remote branch
git push -d origin branchname


merge idea branch (c12) to master and get c13.
 Now merge issue2 branch(c11) to master and get c14

Remote

Add your remote repository as origin
git remote add origin https://github.com/vinodkotiya/bifpcl.git

Where to fetch and push
git remote -v

To push all changes in master branch to remote origin
git push -u origin master
To push all branch to origin
git push origin

Generate SSH Key
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Run SSH agent
$ eval `ssh-agent -s`

Tell agent your key
$ ssh-add ~/.ssh/id_rsa

See SSH Key and copy it
$ tail ~/.ssh/id_rsa.pub

Go to Settings > SSH key in GITHub and paste the above key.

After making any changes locally
git add .
git commit -m "changes and pushing to github"
git push -u origin master

Create and push branchname in remote origin
git push origin branchname

How to merge remote to local
git pull https://github.com/vinodkotiya/bifpcl.git
Pull = Fetch + Merge fetch remote repository and merge with local



Other useful commands

git log

see the change log. for changes see log -p , log --stat, log --pretty=oneline , =short, =full, --since=2.days

git diff

To see the changes in stagged file and working  directory file

git diff --stagged

to compare staging area with last commit.

git rm filename

delete the file and staged

git mv file1 file2

rename and staged

rm -rf .git

delete the git repository


Fork

Fork is GITHUB feature.

You found someone's repo on github. Simply click fork to add it as your remote repo. Clone it locally and work.

What to do if Original Repo changed and you want to sync.


Fetch + Merge can be done in single step Pull.

git remote add upstream url_of_original_repo
git remote -v

Now fetch original repo. It will create new branch called upstream/master
git fetch upstream

Now merge new branch with master
git merge upstream/master

Pull process done. Now push your local changes to your forked version to sync.
git push origin master


What to do if you want to Merge fork Repo to Original one.
You have to create Pull request for original repo owner. Basically owner will fetch your repo as branch. Test it and if found ok then merge with his repo to complete the pull request.


Example

Fork UBCRocket code.
It will add as vinodkotiya/UBCRocket

Now start git bash

git clone https://github.com/vinodkotiya/ubcrocket.git

It will download all data on local machine.
Go to folder
cd ubc*

Edit any file.
touch index.html

Now
git add .

Commit
git commit "page updated"

Push to the forked repository. It will update your version of the forked repository.
git push origin

Click on the new pull request from your git account. Write why you are requesting for pull.






- Written By

Vinod Kotiya

Comments