I have a gitlab server. Gitlab has its own hooks symlinked to every git repo. I wish to be able to tell the difference in between repos when that script is called. I seen this but I don't think it provides any useful information in this case.
Perhaps it may be possible to detect which repo the hook belongs to by figuring out where the script was executed from? (The original script is in ruby) Or possibly to check /home/git/git-data/repositories/<all git users>/<all repos> for the right ref? Either way I do not know how to do that.
In your hook, you can try:
git rev-parse --git-dir
That should give the full path of the bare repo in which the hook (here a post-receive one) is executed.
That is what I used in "Is there a way to get the git root directory in one command?".
Related
I'm trying to clone a repo to my computer. I do the standard
git clone [link to bitbucket repo]
and then call
git branch -a
to see my remote branches, which shows
remotes/origin/develop
which is the branch I want to checkout into. However, when I type
git checkout develop
I get an error that says
error: invalid path '.\api-log\api.log'
and it fails to create the local develop branch. Is this happening because there is something wrong with the file? If so, how can I fix/remove the file so that the clone will go through? All the work is in the develop branch and nothing in the master.
I'm using Windows.
Apologies if this has been answered before but I couldn't find anything.
I don't know exactly why this happen but I suggest you to remove the offending file from the repository history by the wonderful BFG tool.
At this url https://rtyley.github.io/bfg-repo-cleaner/ you can get the software and the documentation.
I'm deploying an app to Heroku, which means pushing to their git repo. When do git push heroku master (or the equivalent remote alias) I get this warning:
WARNING: You're about to push to master, is that what you intended? [y|n]
Which is kinda annoying but not a big deal. However, I'm now scripting deployments so I don't want to have interact with the script - how I do get my bash script to answer y automatically?
I tried doing yes | git push heroku master but that doesn't work.
Agree with #bk2204, I would check if a git hook is being used that you are unaware of.
Git hooks are not version controlled, so make sure you are searching for this at the machine where you get this error.
The git hook may live elsewhere other than the .git directory. Check if git config core.hooksPath is set and if so, it will point to the directory where your git hook is.
The hook file that you are looking for will most likely have the name pre-push. The solution in this case is to remove or rename this hook file, and git won't run it before push.
Nope, no such file
And yet, this is exactly what a .git/hooks/pre-push would do, like this one.
To rule that out, activate (with your local Git 2.25+) trace2.
That will allow you to see what is used on the client side (your PC) by Git:
git config --global trace2.normalTarget ~/log.normal
Try your push, type 'n' (to abort), and check ~/log.normal for clues.
Just another way to solve the problem of automating responses to the prompts. You can use expect to take care of interactive warnings/ prompts.
After writing the deployment script deploy.sh, you can write a expect script and spawn the deploy script in it, for response to
WARNING: You're about to push to master, is that what you intended? [y|n]
message, you can send 'y' from expect.
The following snippet can be taken as example
#!/usr/bin/expect -f
spawn bash ./deploy.sh
expect "WARNING: You're about to push to master, is that what you intended? [y|n]\r"
send -- "y\r"
As is shown in the image,I'm not sure if the failure is caused by some missing property while setting up webstorm .
The issue is not resolved after a lot of efforts.As a learner,I don't know what to do now.
Meanwhile,something seems wrong as shown in git bash.I've no idea whether the two are directly related.
If you have ever faced these difficulties,could you please give me some idea? Even if it's only a web address.
What I want to do is only pushing my code. Anyone who pushed successfully in any other way will be welcomed to share your method.
If I'm being honest I'm not sure that I completely understand your question, but I will supply some information that will hopefully lead you down the right track.
First in the bash shell, cd (change directory) into your project directory like this:
$ cd /c/foo/bar/yourprojectfolder
In your project top most directory, do you have a .git folder? You may have to show hidden folders in windows to see this directory. If not, you need to initialize a repository with the init command.
$ git init
Initialized empty Git repository in C:/foo/bar/yourprojectfolder/.git/
After running this command, you should see a .git folder inside of the directory you changed to (used cd to get to) earlier.
Next, in order to push, you first need a remote repository to push to. Based on your first picture, I believe that you have successfully created a repository on GitHub. If not however, just log into GitHub and click the 'New Repository' button:
Once a repo has been created, you need to add it as a remote to your local git (in git bash). To do this you need a url (either SSH or HTTPS) to your repo. You can find this url inside of your repository in online GitHub. If you are not certain you have set up SSH, it's best to use the HTTPS url. It should look something like this, but the url itself will be different and specific to your repository:
Copy that url to your clipboard, and then back in git bash run:
$ git remote add origin <PASTE YOUR URL HERE>
You need to make an initial commit of your code to have something to push:
$ git add .
$ git commit -m "Initial commit"
Finally, with the origin repo set up and a commit made, you should be able to push to your origin repo
$ git push -u origin master
You should now be able to view your code on GitHub.
I am currently setting up a git schema as described here.
The server in question is running Windows Server 2008 R2, using copSSH and msysGit.
The jist of it is a pair of git repos: one bare repo that is pushed to and then another non-bare repo that contains a live application.
The repo that is pushed to contains a post-update hook that looks as follows:
echo
echo "**** Pushing data to Live Server."
echo
cd /cygdrive/c/Repositories/Live || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
Of note: Live is the non-bare repo which is, as the name implies, live. Live.git is the bare repo which contains the above hook and is pushed to. I was unable to cd to the repo without /cygdrive/, which was uncovered by echoing $pwd in a diagnostic push.
Pull is successfully called in the Live repo, the problem comes in locating the Live.git repo in that update. I get "odd ball" errors that read like:
remote: Pushing data to Live Server.ommand not foundnd not foundle or directory
remote: : not foundpdate-server-infoand not foundand not founddommand not found
hub is defined as a remote repository via the local git shell as both /c/Repositories/Live.git and /cygdrive/c/Repositories/Live.git.
I've replaced "hub" with direct folder paths, even trying things like "../Live.git"
Everything I have tried has ended in a git update failure. All of the attempted paths for Live.git in the update command were attempted via a git bash with the working directory set to the Live repo and worked.
Thank you for any leads or help!
An update:
My schema requires that I pull from the hub repository, it would take an unnecessary amount of room to explain why, but such is the case.
I have done more testing and found more out about my issue:
When I push via SSH to my repository, the prime hub is successfully mounted and the pull command is executed. When said pull command tries to resolve the hub repository it fails (as I detailed above), but it turns out with a series of ls commands in the hook that no folders can be seen. I even ran an ls on /cygdrive/c/ and can only see a folder called usr. I have ensured that the copSSH user has full administrative privileges on the entire file system (only for testing and debugging purposes).
I do not know why my paths have to use the /cygdrive/ path, I do not have cygwin installed besides the cygwin packaged in copSSH. Is this indicative of a problem in my configuration? or is this normal for copSSH + msysGit setups? How is it possible that I can mount the prime repository from the hook, even if ls will not list the repositories folder?
You shouldn't need /cygdrive in paths with msysgit, unless you also have cygwin installed (in which case the combination of msysgit mingw and cygwin might be the source of your problem)
You shouldn't try to run git pull from a repo hook. While some people will say that it works fine, it does not and the behavior can be unpredictable due to various factors.
Instead you should use a method such as this one. http://toroid.org/ams/git-website-howto
That method uses a post-receive hook in a bare repo that calls git checkout to update a directory.
I want to create my own automated dotfiles folder. (I'll be using git to use version control on my dotfiles, but that's irrelevant for the question)
What i simply want is to symbolically link all the files and folders in ~/dotfiles to my home folder. Being not good at all with bash I can't do this. Please help me with this.
I would also appreciate the following features if possible.
Folders are only shallowly linked
My files could be in the dotfiles folder without the actual dot in the file-name (like ~/dotfiles/vimrc rather than ~/dotfiles/.vimrc)
It should be able to ignore some files, like my .git file which are stored in the same folder
Of course if you already know a service providing this, that is at least as good as providing some do-myself commands. Note how I specifically want it to be bash or something that most likely exists on all unix machines (so i guess commands using g++ are fine).
Give this a try:
ln -s ~/dotfiles/* ~
There shouldn't be any need for a loop. Of course, you can use find if you need something recursive.
Edit:
To make the destination files hidden:
for f in ~/dotfiles/*
do
ln -s "$f" "$HOME/.${f##*/}"
done
I am not sure if I'm getting the question right, but if you looking for symlinks of dir-content, try
for f in `ls -1 .dotfiles`
do
ln -s .dotfiles/$f ~/$f
done
maybe that already does the trick
For the sake of managing dotfiles, I really like Zach Holman's approach. I've made the same thing with my dotfiles which you can find it here :)
https://github.com/rhacker/dotFiles
Maybe you are looking for a dotfiles manager, I will recommend you to check DFM (dotfiles manager). DFM addresses the problem you have in a very clean way:
Here is my dotfiles selection using dfm: vicente's dotfiles
Github official repository DFM site
Atlassian has a tutorial on using a git work tree instead of symlinks. The approach uses:
a bare git repository in a side folder (such as $HOME/.cfg or $HOME/dotfiles), and
a config bash alias to execute git commands that manage the configuration files.
For instance, you can run config status to check which files have been modified, config checkout to get the files in the repository and config commit to update the repository. It requires only git and the bash.
I was also looking for some way to set up a new machine in a minimal number of steps, after spending some time I found that almost all the developers use git to store and share these files and symlinks to sync them.
Well, symlinks works, but it isn’t the best way to sync your local files to the git repository. There is a much better solution to this, written by people at Atlassian – https://www.atlassian.com/git/tutorials/dotfiles.
So, to git bare repository is the best and most elegant way to sync your files with your remote copy create a bash script to automate installation and set up.
Managing dotfiles
The trick to managing these dotfiles is by creating a bare git repository. If you are starting from scratch and have not tracked your dotfiles before, make a bare repository in the $HOME directory.
git init --bare $HOME/.dotfiles
Just to make it easier to use we’ll alias this to dotfiles which we will use instead of regular git to interact with our dotfiles repository.
alias dotfiles="/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME"
Now we are good to track our dotfiles using the dotfiles command, some of the examples are:
# to check the version history
dotfiles log
# to check the status of the tracked and untracked files
dotfiles status
# to add a file for tracking
dotfiles commit .vimrc -m ".vimrc added"
# push new files or changes to the github
dotfiles push origin main
Use Cases and Advantages of dotfiles
This method of managing and sharing has various advantages some of them are listed below.
Easy setup
Set up of a new machine can be a time consuming task, but with this method we can to use our personalized configs in under a minute. We just need to clone the repository and source the .bashrc or .zshrc file.
git clone --bare https://github.com/<username>/dotfiles.git $HOME/.dotfiles && source ~/.zshrc
Versioned dotfiles
Best for experimenting with new configurations and keep the change history (Basically all the pros of using git)
# to check the version history
dotfiles log
Share on Multiple devices
Share the same configs of multiple devices with minimal changes using branch, create a branch for your new machine, example:-
# Create configurations specific to your aws machines
dotfiles checkout -b aws
Profiles for dotfiles
Create configs based on your environment using branch, create a branch and configure according to you work env.
# Manage multiple profiles - check out to the work profile
dotfiles checkout work
I also use this way to sync and store my dotfiles, see my dotfiles repository and can read at Storing dotfiles with Git where I wrote about managing for multiple devices.
You could also use dotfile_manager. It allows you to set up a custom path for every symlink you want to create. So with this, you can easily ignore some files and add the . as a prefix to other files.
In your case you would setup the config file dotfile_manager.yaml to contain
symlinks:
- vimrc: ~/.vimrc
Full disclosure: I am the author of this package and use it every day.