Deploy from GitHub? - github

Can I deploy directly from GitHub to my (debian linux) server? Is there a way of transmitting code from GitHub to my server automatically after each commit? And also manipulating a config file?

Clone the repository on server, Run a cronjob on the server every 1 or 2 minutes(or any interval depending on the frequency of your commits) and update the repo. That should be enough. But that's not advisable on the production server. You could do it on testing or staging server though.

Bibhas' answer above is correct although, if you're not the only person collaborating on the repository, you may want to consider using git tags to indicate release-able code and trigger the update only when a new tag appears.
To do this, tag your latest commit on your dev machine and push it:
git tag -a v1.0 -m"Initial tag"
git push origin --tags
Then, on your server:
git remote update && git checkout v1.0
Then, your cron script should do the following:
Get the latest from Github:cd $REPO && git remote update
Get the ref of the current HEAD (assumes you are ONLY checking out to tags):current=$(git rev-parse HEAD)
Get the ref of the latest tag:latest=$(git rev-list --tags | head -1)
And finally, if $current is not equal to $latest, check out the latest tag:git checkout $(git tag --points-at $latest)

Related

Github Simple Commit Issue

I made modifications to my github repo on the actual website rather than the terminal. Now, I can't commit anything locally from my computer to my terminal because it says the files stored locally are not in sync with the github repo. How can I fix this so I can push my changes in terminal? Can I undo my previous commits that I did on the website?
(Optional) If you've some modifications locally, stash them first:
$ git stash
Because you've made some modifications at remote repo, you need to pull them down before pushing new commits (fix conflicts one by one if you got in this step):
$ git pull origin your_branch
Now your local branch & remote branch are in same stage, get back previously stashed modifications back (if you did step #1 before):
$ git stash pop
$ git add .
$ git commit -m "commit msg here"
It's OK to push local modifications to remote then:
$ git push origin your_branch
Btw, if you did modification at remote repo BY MISTAKE, and just want to use local repo as latest, you can push local repo to overwrite remote one (make sure remote repo's branch is not protected by server):
// !!! Use it wisely & carefully, cause it will overwrite the whole branch at remote side.
//
$ git push -f origin your_branch

git(hub) lost all my changes in group project

I am working on an eclipse project with two friends. We use Git(Hub) to work as efficient as possible. Here is the problem: I worked on the project and uploaded the changes. Unfortunately, my friends were not able to see my modifications. Nevertheless, I was still able to see my new version in eclipse. Now I tried to upload it again but "there was nothing to upload".
Then I used git fetch and rebase to see if something would happen.
Unfortunately, all changes are gone now. I used git commit --amend and they "found a swap file by the name xx with the date of my last upload!".
Does anyone know how can I get back to my working version now?
If you didn't push your changes after messed up local history, then reset your local with remote.
$ git branch <branch-name> # backup the branch for safety
$ git fetch # sync with remote
$ git reset --hard origin/<branch-name> # reset local branch with remote branch
Alternate: git reflog will show you the whole git history you executed the commands. Copy the last working commit-hash you want to go back.
$ git reflog
Checkout to that commit.
$ git checkout <commit-hash>
$ git log # see the commit history
If all things are ok. Then checkout to a new branch. If you do any change in new branch then do Add, Commit and Push or, just Push to remote.
$ git checkout -b new-branch # create a new branch called 'new-branch' and checkout to that branch
$ git add .
$ git commit -m 'message'
$ git push origin HEAD # push to remote new-branch

How to push and clone yii2 projects to github?

I have developed a simple web-app with yii2 and pushed it to my github repository. I tried to clone it to another folder and test it, but it didn't work.
Something tells me that it is because I get my yii2 from an archive without composer and when I try to clone it, I use composer install command to get vendor folder and autoload file and it doesn't do it right.
Why is it happening and how can I push my web-apps properly to github so that everyone can clone and start them? Thanks in advance.
Once you've done the Yii2 app ready into you local, kindly follow below basic commands of Git.
Git Basic Commands
Git Checkout:
$ git clone CHECKOUT_URL
To check git files status:
$ git status
To add all file into git:
$ git add *
To add selected file into git:
$ git add filename1, filename2
To commit all added/updated/deleted files into Git:
$ git commit -m "initial commit" *
To commit selected file into git
$ git commit -m "initial commit" filename1, folder1
To push committed files into Git master branch:
$ git push -u origin master
To see all exists branches:
$ git branch
To create new branch:
$ git branch changes
To select branch:
$ git checkout changes
To commit into selected branch “changes”:
$ git push origin changes
Other Git Commands:
$ git --help
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG

Adding to Github from Visual Studio 2013 not working as documented

This is the online reference I am using. However when I enter the remote repository and hit publish I get an error
You cannot publish local branch master to the remote repository origin
because a branch with the same name already exists there. You might
want to rename your local branch and try again.
I dont want to rename anything as yet. I want the first version of the code to go into the master branch and at the same time create an upstream tracking branch locally.
Then I tried using the command line only. After creating a fresh repository, I ran the following commands
$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin <url>
$ git push --force
This worked but now I have all my obj,bin,packages directories along with it. I don't want all those directories to go. Editing the git ignore did not help either. What I am doing wrong? Its taken more twice the amount of time to get the code into the repository than it has taken to write the code!
I only want my sources in the repository and have a tracking local branch to begin with.

New to Git Hub I have code on my local system and I want to get the latest code there committed by other team member how I could do that

I need a command to update the latest code from the Master repository. Like SVN, we do an update and it will give you latest code.
I am trying to use
sudo git pull origin master
but it says already up to date. I have tried to do
git reset --hard HEAD
sudo git pull origin master
as well but it is also not working.
Try to check if you are on the right branch (master):
git branch
It should look like this:
* master
If it isn't, type:
git checkout master