Here is quick guide on using Git with GitHub.
Getting Git for Windows
- Git for Windows can be downloaded from https://gitforwindows.org
- Go through the installation process after downloading
- By default Git Bash and GUI will be integrated with Windows Explorer, but can be disabled while installing.
- You may keep default options during installation process, default options would work for most of users.
Setting up GitHub Account and Settings
- Open https://github.com/ and create your account or Login if you already have account.
- You have to add a project on GitHub where you would be creating repositories, each project can have multiple repositories and branches
- Click on create repository to add and commit repository immediately.
- You may directly add files and folders to GitHub using Web Portal GUI or by using CLI also known as Git Bash.
- Git bash was installed as part of Git installation.
- Adding files from Web Portal is very simple, you may simply Upload or Create New file.
- Also, note that using Git Hub does not require you to install Git for Windows as it is completely web based.
- You would get option to Upload or Create New file as soon as you go into Repository as shown below:
- Once you select the file(s) as shown above, the file(s) should be committed
- Add comments to commit and press Commit Changes to apply changes, this will complete the check in process using URL or Web Portal of GitHub.
This process first requires you to create Clone of Repository from GitHub to local and then make your changes in local repository, once done then you can upload your changes to GitHub using Git Bash. Step by step process is given below.
- Open Git Bash program. (Git Bash accepts linux like commands, for example: cd, pwd, ls, etc.)
- If you would like to change current directory to C drive then command will be “cd /c”
- Same way if you would like to see content of current directory then command is “ls”
- To get current directory (aka Working Directory) path the command “pwd”
- The first step requires to clone the repository from GitHub.
- In this demonstration the directory used to keep clone is c:\github hence the command to change directory will be “cd /c/github”.
- Also you would require git URL of your repository. You may get git URL from github repository page, by selecting option Clone or download as per screenshot below
- Make sure that you are in working directory where you want to clone the Repository and execute git clone command “git clone [git URL]”
- Git will use your current identity (Login name or ID) against changes and activities you would perform, you may want to change it to your preferred user name using config command.
- If you add global switch to config command the changes will be applied to all repositories, otherwise changes will be applied to current repository only.
- Global config below
- Before you could make changes like adding files etc. you will have to checkout the repository. In previous steps you cloned the repository.
- Command to checkout repository is “git checkout master” (master is main copy and you can create branches from master, for example development or test branch)
- Now you can add files to the working directory or create new, once done add file(s) to repository “git add [filename]”
- The next step is to commit changes in local repository using command “git commit –m “comments”
- The final step in the process is to push the changes and the command is “git push”
- To validate, you may go to Git Hub URL and you should see latest changes you made from Git Bash.