{"id":12,"date":"2013-09-23T16:48:31","date_gmt":"2013-09-23T16:48:31","guid":{"rendered":"http:\/\/linux.mycustomcycle.com\/?p=12"},"modified":"2015-02-19T19:35:29","modified_gmt":"2015-02-19T19:35:29","slug":"git","status":"publish","type":"post","link":"http:\/\/linux.suriyasuneel.com\/?p=12","title":{"rendered":"Git"},"content":{"rendered":"<h3>How to use Git<\/h3>\n<ol>\n<li>Create a remote repository<\/li>\n<li>Create a local repository<\/li>\n<li>Add files to the local repository<\/li>\n<li>push the local files to the remote repository<\/li>\n<\/ol>\n<h3>Create a remote repository<\/h3>\n<p>How to setup a git server is in a different page.<br \/>\nI&#8217;m going to concentrate on how to create a repository in a remote server which is already setup for the git.<br \/>\nOur goal is to create a remote repository for the projects makefiles. This has files that automate my build processes.<\/p>\n<ol>\n<li>Login to the remote server as the git user<\/li>\n<li>go to the root folder of your git repositories\n<ul>\n<li>in my case it will be \/home\/git<\/li>\n<\/ul>\n<\/li>\n<li>create a folder called makefiles.git\n<pre>$mkdir makefiles.git<\/pre>\n<\/li>\n<li>change to the folder as\n<pre>$cd makefiles.git<\/pre>\n<\/li>\n<li>initialize the repository inside the makefiles.git folder as\n<pre>$git --bare init<\/pre>\n<\/li>\n<\/ol>\n<h3>Setup the local repository<\/h3>\n<p>If you are adding a folder which contains the files for your project then go that folder.<\/p>\n<ol>\n<li>Initialize git in the folder as\n<pre>$git init<\/pre>\n<\/li>\n<li>Mark to add all the files to the git as\n<pre>$git add *<\/pre>\n<\/li>\n<li>Add all the files by committing the add as\n<pre>$git commit -a<\/pre>\n<\/li>\n<\/ol>\n<h3>Setting the remote server for the local repository<\/h3>\n<p>We need to setup the local repository with the information about the remote repository<\/p>\n<ol>\n<li>first clear any settings about the remote server as\n<pre>$ git remote rm origin<\/pre>\n<\/li>\n<li>now add the remote server name as\n<pre>$ git remote add origin ssh:\/\/git@jaya.homelinux.org\/home\/git\/makefiles.git<\/pre>\n<\/li>\n<li>if you are ready, send all the files to the remote server as\n<pre>$ git push -u origin master<\/pre>\n<p>After this command both the remote and the local repositories are identical. You can either choose to continue working<br \/>\nor delete the local repository and get a copy from the remote<\/li>\n<\/ol>\n<h3>Working with the project<\/h3>\n<p>You would want to have a copy of the entire repository which can be done as follows<\/p>\n<pre>$ git clone ssh:\/\/git@jaya.homelinux.org\/home\/git\/makefiles.git<\/pre>\n<h3>Git Branches<\/h3>\n<p>the branches that you create are local and then you can send those branches online by pushing the changes to the repository.<\/p>\n<pre>$git branch &lt;branch_name&gt;<\/pre>\n<p>will create a branch branch_name for you now we can make a branch active by checkingout that branch<\/p>\n<pre>$git checkout &lt;branch_name&gt;<\/pre>\n<p>make sure that the changes on master appear in your new branch as follows<\/p>\n<pre>$git rebase master<\/pre>\n<p>now you can push these changes to the remote branch as follows<\/p>\n<pre>$git push origin &lt;branch_name&gt;<\/pre>\n<h3>Merge<\/h3>\n<p>This is when you are working with a different branch. say you are working with a branch br_9_22_2012 and you want to merge into master.<br \/>\nFirst switch to master<\/p>\n<pre>$git checkout master<\/pre>\n<p>now merge the br_9_22_2012 to the master as follows<\/p>\n<pre>$git merge br_9_22_2012<\/pre>\n<p>now commit this these changes to the source control<\/p>\n<pre>$git commit -a -m \"merge message\"<\/pre>\n<p>Once all the changes are merged to the master, now you can push these to the server as all these changes are local to the disk<\/p>\n<pre>$git push -u origin master<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to use Git Create a remote repository Create a local repository Add files to the local repository push the local files to the remote repository Create a remote repository How to setup a git server is in a different page. I&#8217;m going to concentrate on how to create a repository in a remote server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=\/wp\/v2\/posts\/12"}],"collection":[{"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12"}],"version-history":[{"count":1,"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":13,"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=\/wp\/v2\/posts\/12\/revisions\/13"}],"wp:attachment":[{"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/linux.suriyasuneel.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}