Background
There are multiple code versioning tools. Some of them are SVN, Git, Mercurial, Perforce etc. In this post we will see how can we install git on windows and use it to create a local repository of a existing repository on github.
For installing git on Linux from source you can refer to one of my earlier posts -
Installation
- Download the installer from the official git website.
- Run the installer.
- If you are a beginner leave every setting in the installation workflow to default except probably the screen that says add git to the classath (This would alter your $PATH env variable).
- Finally click on finish to complete the intallation.
Screenshots for installation
Quick way to know if git is installed in your system is to open your command prompt and type git or git --version
If you see above output you have successfully installed git on your System.
Cloning a Git repository from Github
I have a repository on github that I had created fir creating a simple tic-tac-toe android application some time back. I am going to clone the same one. You can view the project at https://github.com/aniket91/TicTacToe
To clone a repository you have to use git clone repoUrl command.
- C:\Users\athakur\GitSources>git clone https://github.com/aniket91/TicTacToe.git
Pushing changed to Github repository
Prior to pushing your changes you need to be aware of the changes that you have made. For that you can use git status command.
- git status
Before pushing you need to commit your changes. Use
- git commit -a OR
- git commit -m "git commit message"
If you want to redo your commit then you need to execute -
- git reset --soft HEAD~1
To push your changes you need to execute git push command.
- git push
You can see your commit changes on github. Below is the screenshot for my demo changes in this post.
Confused with master, remotes, origin?
You can run the following command to know more about repos your git knows -
- git branch -a
Here, master is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin. remotes/origin/HEAD is the default branch for the remote named origin. This lets you simply say origin instead of origin/master.
So master is the branch name where as origin in the remote repo name.
Avoid Merge Commits
Whenever you have unpushed commits on your local and you try to do a git pull after those commits it will create a merge commit .To avoid it follow one of the below mentioned methods,
- run git pull --rebase
- To avoid running it with the rebase flag and to make the above the default behavior when pulling changes, git config --global branch.autosetuprebase always
- In SourceTree under tools->options/preferences under the Git tab select "Use rebase instead of merge by default for tracked branches"
My Git Repositories
Related Links
- Installing git in Ubuntu (OSFG)
- Installing Git on CentOS from sources(OSFG)
- Installing Mercurial on Linux
- How to Install Kdiff3 on Ubuntu
- Pushing from local repository to GitHub hosted remote (SO)
- error: The requested URL returned error: 403 Forbidden while accessing
- Undo the last Git commit?
- What is the difference between Forking and Cloning on GitHub?(SO)
- Are git forks actually git clones?(SO)
- How to update a GitHub forked repository?(SO)
- Checking for existing SSH keys
- Generating a new SSH key and adding it to the ssh-agent
- Adding a new SSH key to your GitHub account
No comments:
Post a Comment