Â
Always!!!
$ sudo apt-get update
$ sudo apt-get install git
Â
$ git config --global user.name "Test Name"
$ git config --global user.email "[email protected]"
Â
This is important because it allows other people to identify you. Build systems like Jenkins, Bamboo etc. use this identification to do a lot more.
Â
You can customise the identity for a particular repo as well
$ cd /your/path/to/the/repo
$ git config user.name "Another Name"
$ git config user.email "[email protected]"
$ git config --global core.editor vim
Â
In order to merge changes and view them. Personally, I use Eclipse
$ git config --global merge.tool vimdiff
To view all the configurations
$ git config --list
All the changes are stored in ~/.gitconfig file. Go check them out.
$ mkdir ~/projects/test-project
$ cd ~/projects/test-project
$ git init
Initialized empty Git repository in ~/projects/test-project/.git/
The command "git init" creates a .git/ folder in the folder. This is where all of git's data is stored. If you delete this folder, you'll delete all the history and tracking information.
Â
All configurations pertinent to this repo is stored in .git/config file. Open it in your favourite editor and check it out.
Untracked files
Staging Area
Local Git tree
Remote Git tree
Every file/change starts without git knowing about it.
If you want to commit a change, you would put it in this staging area to tell Git that it should be interested in this.
When you commit the change, only the local linked list is modified. This design allows for very powerful semantics (covered later)
Finally, the change is pushed to the remote repository. It is now available to other devs on the team.
All files start out being untracked. These are new files that are created in the folder.
Let's create a new file in our folder
Â
$ echo "Initial content" > README.md
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
Git knows what it doesn't know :D
The staging area is a buffer area where you can add files/changes to files before actually committing them. This feature allows you to add files one-by-one and inspect the changes before actually committing it.
Â
$ git add README.md
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
Git now knows that these changes will be committed going forward.
Git tries to keep changes locally unless specifically asked to share with everyone. When we commit a file, it's only changed in the local git tree.
$ git commit -m "Initial commit"
[master (root-commit) 29c5223] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
$ git status
On branch master
nothing to commit, working directory clean
The flag -m is followed by the commit message. This should be populated by the reason for the change. Other devs will see this commit message to understand why this change was made.
If you haven't already, head to Github and create a project there. We'll push our changes to the world!
$ git push origin master