I am sure most of the web developers would have heard about the famous repository service, Github. I have been using github for my projects lately and would like to share some quick and useful info on how to setup a project in github, and how to sync it with your local project.
I assume that you are using a windows machine, have xampp/wampp installed on it, along with GIT GUI/Git Bash softwares (you can download from: Here), and you have a github account online. So lets begin with creating a new project on github.
1. Login to Github and create a new repository. Do not initialize the new repository with README, license, or gitignore files for now. You can add them later.
2. Create a new php project in your localhost, with a couple php/html files.
3. Now right click inside your local project folder and select “Git Bash Here”. You will get a Git command prompt.
4. Initialize the local project directory as a Git repository, by typing: git init
5. Add all the files in your new local repository, in order to make them ready to be pushed to remote git repository: git add .
6. Commit the files that you have added above: git commit -m ‘First commit’
7. Copy the HTTPS clone URL of your remote repository on github.
8. In the Command prompt, add the URL for the remote repository where your local repository will be pushed: git remote add origin REMOTE_REPOSITORY_URL
9. You can verify the new remote URL, by typing: git remote -v
10. Push the changes in your local repository to GitHub repository: git push origin master
At this stage, you can check your remote github repository, and it should contain all the files of your local repository.
Below are some of the tips for using Git:
> Clone Git repo to local folder:
1. Go to htdocs folder
2. Right click and select ‘Git Bash Here’
3. Type: git clone HTTPS_clone_URL_of_your_GIT_repository
4. Enter github credentials and you get GIT repo folder in htdocs
> Force GIT to override all remote files:
git push -f origin master
> Set git author & email:
git config –global user.name Tester
git config –global user.email firstname.lastname@example.org
> Upload all changes from local repo to github repo:
1. From the local repository folder, right click and select ‘Git GUI Here/Git Commit Tool’.
2. There, select the files you want to upload, under ‘Unstaged Changes’ and click ‘Stage Changed’ button. (You can initially click on ‘Rescan’ button to check what files are modified and not uploaded yet.)
3. Then write a Commit Message and click the ‘Commit’ button.
4. Now right click in the folder again and select ‘Git Bash Here’.
5. Type: git push origin master and enter your credentials. Done.
Note: You may need to do a ‘git pull origin master’ prior to push.