07 Feb 2014
This post is a continuation of my post in regards to Git branching. Below are some tips I gather around when using git.
Below commands are used to get around with git. These are used on daily basis to get work done.
The first most important command to initialize a repository. It will make the .git folder inside your codebase. Next used command with this command it the git add command.
Clone command allows you to clone a repository from another repository (Github mostly). One key difference if you are coming from the SVN world is that - git clone will copy everything about the repository from the server to the client. Also if you have setup SSH keys for Github it’s better to add the ssh clone url rather than the https one.
After cloning git will create a remote called origin which points to repo you cloned.
Git allows you to specifically mention which files are source controlled and which files are not. You can add a file to the repository and then the changes will be tracked in subsequent usage. ’.’ can also be used to add everything in the directory and wild cards such as ’.java’ are allowed.
In Git there is a space called staging area. Index is a staging area (sometimes it’s referred as the staging area as well) for changes to files. When we perform a
git add . - git essentially add whatever specified in the command to the index.
A basic command to get the status of the index. This command is used to find
- Modified files
- New files
- Current branch
Complementing to the Git add is the status which is used check the index before committing whether you have everything in order. Git diff can also be used to compare git working directory and the index.
When we say
git commit - changes in the index are added to the repository. By including a log message to the commit- we can make it meaningful for later use.
Couple of useful flags used with this command are
- -a - add changes of the working directory for the commit (basically running a git add .)
- -m - State the message inline -
git -m "First commit"
- –dry-run - is used to run the commit command with all the parameters to see what happens to check. When using this flag nothing is committed to the repo.
I’ll be having another post about git tips since this post is getting too long.
Till next time mate,
Dulitha at 00:16