Monday, December 8, 2008

Git And GitHub Frequently Used Commads

GIT is a Distributed Version Control System, it is rapidly gaining popularity on other version control systems namely Subversion, CVS, due to its easy of use, and its rapid commit speed.
It creates a new way of adressing complexties on a OpenSource Project, where earlier developers had to wait for days to checkin their code and deal with complex merging issues.

With GIT, all those are things of the past, we can focus on pure business logic or the code we are concerned. We just have to merge the changes with trusted resources and not get bothered by tons of other people changes.

There are very excellent articles and videos which Cover GIT in detail, My goal here is to display those commands which our team has been using more often

Initialization Commands
  • git config --global github.user <>
  • git config --global <>
  • git config --global color.branch "auto"
  • git config --global color.status "auto"
  • git config --global color.diff "auto"
  • git clone
General Commands
  • git log
  • git status
  • git diff, shows the difference between curret and head version
  • git diff "@{yesterday}" , shows changes since yesterday
  • dit whatchanged --since="2 weeks ago"
  • gitk, to open the git GUI
Branch Commads
  • git checkout -b $samplebranch , Creates a branch named samplebranch and switches to it
  • git checkout $samplebranch, Just switches to a new branch
  • git branch -d $branch, deletes the branch
  • git branch -a : shows all branches local and remote
  • git branch -r : show all remote branches
Remote Repo Commands
  • git remote add <remoterepo>>/>.git , Adds a remote repository (e.g forked one from the main) to your machine
  • git remote rm deletes the remote directory
  • git remote -v : displays all the remote repositories
Adding & Reverting & Commiting Changes on GIT
  • git add . , adds all the changed /new files to the repo
  • git reset --hard HEAD , Reverts all uncommited changes
  • git clean -df , Remove any files in your working directory that were not added to git e.g autogenerated files.
  • git revert , Reverts to previous commit.
  • git commit -m "my first commit" to commit the files
  • git checkout <>, to revert a individual file
Adding Tags at Regular Intervals
Its good to add tags lets say at different phases of project or while branching out,
  • git tag -a -m "branched out version1" version1 , this will tag the last commit with the tag version1
  • git tag , will display the tags
  • git push origin --tags , will push the tags to the remote origin
Pull and Merge Changes from other repos
The following steps summarize the commads need to pull changes from other forked branches to your local branch and push it to your remote github repo
  • git remote add
  • git remove -v
  • git checkout -b auser/master
  • git branch
  • git pull auserrepo master
  • git checkout master
  • git merge auser/master ,Note: if there are any conflicts open the files and resolve them
  • git add . , This step is need to add any resolved conflict files
  • git commit -m "your commits about successful merge"
  • git push origin master , to push your changes to the github origin repo
Creating Remote Branches
To create a remote branch, there are many ways to approach
  • Create a local branch
  • git push origin master:refs/heads/R1.2 : to create a branch name R1.2 on remote origin
  • git checkout -b R1.2
  • git pull origin R1.2 : to pull changes from remote R1.2 branch

Git Ignore
echo stacktrace.log >> .gitignore , adds stacktrace.log to .gitignore directory
Note: I haven't seen this working yet, hopefully soon it should work

Some Good Articles on GIT

No comments:

Post a Comment