Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Thursday, March 16, 2017

How to remove deleted files from git

So I deleted few files from my repo and yet I still saw them each time I executed 'git status', I was annoyed so I decided to fix it!

Here is what you do: You need to remove the deleted files from git and then issue another commit to finalize the change.
First you need to find the name of these files. Here is a script to do it

git status | grep deleted | awk '{print $3}'

this would issue 'git status' command, find all that say deleted, and then extract file names.

Now feed that to git remove command, like so

git rm `git status | grep deleted | awk '{print $3}'`

Now commit the change and you are all set!

Tuesday, May 27, 2014

How to create remote git repo from local project

1. create files/projects/etc.
2. cd into the directory and run
    git init

3. add all of your files into git
    git add *

4. commit it
    git commit -m "Initial commit"

5. for kicks, run following command to see if you have any attached remote repos. you should not see anything
    git remote

< see below "On your remote server" section >

6. Attach remote repo
    git remote add origin ssh://user@ip.add.re.ss:22/opt/git_repos/foo-project.git

7. if you mess up, run
    git remote remove origin

8. now run #5 command and you should see origin there

9. now push your local changes to repo for everyone to see
    git push -u origin master

10. after that, you can just call
    git push

On your remote server
a. sudo su -
b. cd <path_to_git_repos>
c. mkdir foo-project.git
d. cd foo-project.git
e. git init --shared=777 --bare
if you wont specify --shared=777 you wont be able to write to it due to permission issues. If you are stuck on Writing object part during your git push, that's the reason.

Reference:
http://qugstart.com/blog/ruby-and-rails/create-a-new-git-remote-repository-from-some-local-files-or-local-git-repository/

Thursday, March 13, 2014

Puppet files and git.


If you have puppet files just sitting around on the server and random people changing manifests or uploading files without any type of coordination, that can lead to all kinds of issues. So let's go ahead and bring some order to it.

First, install git on the puppet server
sudo yum install git
Navigate to the directory where we have our puppet files.
cd /etc/puppet/

Initialize git there
git init

Add and commit all files
git add .
git commit -m "Initial commit"


Create bare repository to make it easier for people to clone new puppet repo
git clone --bare . ../puppet-repo.git

Add a pointer to your new bare repo using the origin name
git remote add origin ../puppet-repo.git/

Now open a command prompt on your local machine and execute following command to clone aka get puppet files on your machine. (Before that I created a directory to hold the data)
git clone user_name@host_name_or_ip:/location/of/puppet-repo.git

You will be asked if you want to connect, type 'yes' and provide your password. After which you can monitor the progress of your clone process... Might take a while depending on your network connection and data amount.

Now to avoid making all changes in the notepad, you can install Geppetto, which is A Puppet IDE and availabe as Eclipse plugin. The installation of Geppetto is quite straightforward. If you have an existing Eclipse, its easy to load up Geppetto within it:
•Help —> Install new Software
•Add —> Location = http://download.cloudsmith.com/geppetto/updates
•Select “Geppetto” from the list of potential downloads
•Finish
•Accept any Licenses
•Reload Eclipse

At the time of this writing, there is no option to import already existing Puppet project into Geppetto, so you have two options. Create and tweak .project file in your puppet project folder and then import existing project or you will need to import the project as a 'file system'. Geppetto will then create the xml file for you. I chose to import it as a file system...

Go ahead and play around with your modules and manifests...

Now that you made your changes go ahead and add them to the main repo.
Run git status to verify your changes, run git add . to stage them, and finally run git commit -a to commit. Now to add that to the main repo run git push

If you are getting an exception stating that "insufficient permission for adding an obkect to repository database", that means that you need to make further changes on the main server. Nothing big, just need to make sure that you have read/write set up right.
ssh to server
cd puppet-repo.git

sudo chmod -R g+ws *
sudo chgrp -R mygroup * ---> to find your group run: groups <username>

Try git push again. It should work.

Now that you successfully pushed your updates, go ahead and pull them on the server.

ssh to server
cd to the location of you puppet files and execute
git pull to get the updates.

You shall see the changes made...

This is a two way street. If you must make changes on the server, you can. You just need to commit and push it for others to see your changes.

Now this won't stop someone from modifying the files directly on the server and not committing them, but hey at least it is a start and you can remove the access of average user to this and force people to use git push to commit their changes.

No more Wild West!