Github is an online service that hosts git projects and helps achieve social coding. Sign up for Github. After you have signed up and logged in, create a new repository. Once the repository has been created in Github, start the Git Bash/Terminal and navigate to a folder in your local machine where you want to store your project files.
- You can use the Change Directory – cd and Make Directory – mkdir commands in both Git Bash and Terminal to navigate to the directory.
- Once you have navigated to the directory, initialize Git in that folder by using the command git init
- To track all files, you can use the git add . command (notice the dot in the end).
- Next, the files need to be committed to the local repository. The command is git commit –m “message”. The –m “message” requires a message every time you commit, to uniquely identify the versions and you need to specify it within quotes.
- The command for this is : git remote add origin https://github.com/username/repo-name.git (where the username is your Github username and the repo-name is your repository name.)
The files now need to be sent or pushed to the server. This enables the server to maintain the latest version of the code every time.
- The command to send the latest commit version to the server is git push
If the server has a newer version of the project, it will not allow a push until you have a newer version. So the push fails and Git asks you to do a pull before you can push.
- The command for a pull from the server is git pull
You will now be able to push your commits to the server once you have a newer version.
No comments:
Post a Comment