Showing posts with label GIT Commands. Show all posts
Showing posts with label GIT Commands. Show all posts

Friday, March 6, 2015

Pulling your co-worker forked remote branch


> git remote add coworker https://github.com/coworker/studiorepo.git
> git fetch coworker
> git checkout --track coworker/foo

This will setup a local branch foo, tracking the remote branch coworker/foo. So when your coworker has made some changes, you can easily pull them.


> git pull
> git checkout foo

This will pull the latest changes. This is especially required when you wanted to pull the code and review it directly without really disturbing own repo. This will avoid setting up one more repository as well.


Monday, March 2, 2015

GIT: some useful git commands for my reference

To delete a local branch:
> git branch -d <branch name>


To checkout to remote branch
> git fetch
> git checkout <branchname>

Monday, July 1, 2013

GIT Remote Branches

You might want to figure out, what are the branches exist in the git remote repository,then you want to choose the specific one which you are looking and check them out and merge them into a local repository.

The easiest way do it:
>git branch <-a/-r>

-a => List down all branches- remote and local
-r => List down only remote branches.

Example:

K1205@K1205 /d/Work/KIDE/jsdebugger (master)
$ git branch
  Dev-5.0
  jsdebugger_plugins-master.06
* master

K1205@K1205 /d/Work/KIDE/jsdebugger (master)
$ git branch -a
  Dev-5.0
  jsdebugger_plugins-master.06
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/JSD-BETA-5.0.05
  remotes/origin/JSD-BETA-5.0.06
  remotes/origin/JSD-GA-5.0.01
  remotes/origin/JSD-GA-5.0.02
  remotes/origin/JSD-GA-5.0.3
  remotes/origin/JSD-GM-5.0
  remotes/origin/JSD-QA-5.0.01
  remotes/origin/JSD-QA-5.0.02
  remotes/origin/JSD-QA-5.0.03
  remotes/origin/JSD-QA-5.0.04
  remotes/origin/JSD-QA-5.0.05
  remotes/origin/JSD-QA-5.0.06
  remotes/origin/JSD-QA-5.0.06.01
  remotes/origin/jsdebugger_plugin-master.01
  remotes/origin/jsdebugger_plugins-master.01
  remotes/origin/jsdebugger_plugins-master.02
  remotes/origin/jsdebugger_plugins-master.03
  remotes/origin/jsdebugger_plugins-master.04
  remotes/origin/jsdebugger_plugins-master.05
  remotes/origin/jsdebugger_plugins-master.06
  remotes/origin/master

K1205@K1205 /d/Work/KIDE/jsdebugger (master)
$ git branch -r
  origin/HEAD -> origin/master
  origin/JSD-BETA-5.0.05
  origin/JSD-BETA-5.0.06
  origin/JSD-GA-5.0.01
  origin/JSD-GA-5.0.02
  origin/JSD-GA-5.0.3
  origin/JSD-GM-5.0
  origin/JSD-QA-5.0.01
  origin/JSD-QA-5.0.02
  origin/JSD-QA-5.0.03
  origin/JSD-QA-5.0.04
  origin/JSD-QA-5.0.05
  origin/JSD-QA-5.0.06
  origin/JSD-QA-5.0.06.01
  origin/jsdebugger_plugin-master.01
  origin/jsdebugger_plugins-master.01
  origin/jsdebugger_plugins-master.02
  origin/jsdebugger_plugins-master.03
  origin/jsdebugger_plugins-master.04
  origin/jsdebugger_plugins-master.05
  origin/jsdebugger_plugins-master.06
  origin/master

Saturday, September 10, 2011

Working with GIT

 How does it work?
       GIT is a version control system, works completely based on local repository concept. It’s completely different than any other source version control systems like Perforce (I was using this before we migrate to git). It will maintain local repository and central repository and whatever your changes you make to your files will be added to staging Area.
     When you commit your changes it actually records in a local repository as a snapshot and when you push your changes it will be merged with a central repository. Will use fetch concept to get the remote changes to your local repository.

Here you will find a list of GIT commands I generally use it during my development every day. Hope this will help you guys.

1.       Creating a new branch
Ø  git branch  [new branch name] 
Ex: > git branch mylocalJavabranch

2.       Checking existing branches in your local repository.
Ø  git branch
o/p:
    myLocalJavabranch
    javabranch
    Customer-fixes

It will list down all your branches reside in your local repository.

     
3.       Checkout to the branch
Ø  Git checkout  [your branch name]

Ex: git checkout customer-fixes

If you are working with multiple branches. May be you could have created different branches for different features which you have been working with.

4.       Checking the status in your branch- It will show the added files and untracked files.
Ø  Git status

5.       Add unstaged files.
Ø  Git add –all

6.       Commit all your added and modified files to a local repository.
Ø  Git  commit –a  -m “description about your commit”

7.       Fetching from a central repository. It will bring all the modified files from a central repository to local repository.
Ø  Git fetch

8.       It’s always a good idea to fetch and rebase before you push your changes. This will bring all files from repository to your local branch and rebase your local changes on top of it.
Ø  Git rebase  [your remote branch]

Ex: git rebase origin/java

If any conflicts it will try to auto merge the files. If not, user has to merge manually and add that file to staging area so that it will be available for the next commit.

Due to conflicts, if rebase could not continue, use the following command to continue the rebase.
Ø  Git rebase –continue

9.       Push your changes to a central repository.
Ø  Git  push  gerrit  HEAD:refs/for/java

10.   Checking the log history. It will list down all the local commits.
Ø  Git reflog show
                     Every commit will generate a hash id to uniquely identify the commit. To check what you have submitted in that commit use this command.
Ø  Git reflog  [hash id]



Here is the cheat sheet for git @ git-cheat-sheet.pdf


Thanks,
Kondal.