Git Commands And Bitbucket

DWQA QuestionsGit Commands And Bitbucket
Pankaj Staff asked 9 years ago

Bitbucket: web-based hosting service (http://bitbucket.org/). Create free account here.

Free 5 users team and unlimited repository

Git is a distributed revision control and source code management system

Two Types:

Centralized (can be failed sometime and halt all
user’s process) [SVN]
Distributed (create local repository on your
system) [GIT]

WORK FLOW:

local directory >> git add >> code goes to staging area >> git commit (Head) >> push to master

Terms used in GIT:

commits, branches, clone, pull(fetch) ,push,
checkout, HEAD (get head dir and get latest commit revision number)

Installation:

Ubuntu: sudo apt-get install git

Windows: git bash

Commands:

git config –global user.name “pankaj

– Create a new git repository.
git init

-checkout a repository
git clone /path/to/repository

– Add & Commit
git add <filename>
git add *

– Commit Changes
git commit -m “Commit message”

– Push Changes
Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository
git push origin master

HEAD:   current revision

master: is a name commonly given to the main branch

origin: is a name commonly given to the main remote. remote is another repository that you can pull from and push to

Change master to whatever branch you want to push your changes to.

Branches:

Branches are used to develop features isolated from each other. The master branch is the “default” branch when you create a repository.

– create a new branch
git checkout -b feature_x

In two steps:
git branch branch_name
git checkout branch_name

– Delete a branch (move to master before delete
by checkout command)

git branch -d feature_x

– Push the branch to your remote repository
git push origin <branch>

Update & merge:
git pull

Merging:
It is important to remember when merging, that we want to be on the branch that we want to merge to.

git checkout master

– To merge another branch into your active
branch (e.g. master), use

git merge <branch>

git push master origin (gives warning if already some commit code on same line and you didn’t take fresh pull so take pull using git pull)

if conflicts come: resolve it by manually and again add those files and
git add <filename>
git commit
git push and all..

Replace local changes:

In case you did something wrong, replace local changes using the command
git checkout — <filename>

fetch the latest history from the server
git fetch origin

Log:
git log

Go back to Commit:
git checkout <commit>

Go back to original master commit:
git checkout master

Reset: Reset current HEAD to the specified state
git reset –soft c14809fa

Git ignore File:
Create file:
touch .gitignore

add folder name in file for eg. (cache/*)

Help URL And Practice URL:
http://rogerdudler.github.io/git-guide/https://try.github.io/levels/1/challenges/1