Professional Documents
Culture Documents
Git - Guide
Git - Guide
Git - Guide
Git
1. Creating a Repository
Use git init command to create new git repository
$ git init myproject
To publish your repository to remote i.e. Push your project to remote git server
To put your repository on a server we'll start by making a "bare" repository, and upload it to a server.
To create bare repository use
2. Cloning Repository
When we create files inside local repository we need to add this file to stage.
If file not added in stage then git consider it as untracked file.
To check untracked, un-committed file and current git repository status use
$ git status
Now your added files are ready to commit. So commit the files using
$ git commit m commit message
Notes:
Everything whatever we are doing is on local repository (add/commit)
We need to push those changes later to remote repository.
To push your local repository committed changes to remote git repository use
$ git push origin master #Here master is our current working branch
To checkout branch
$ git checkout branch-name
Branch is not available to others unless you push the branch to your remote repository
To push branch to remote use
$ git push origin branch-name
Merge branches - suppose you are working on dev branch and all development for the module is
done and now you want to put that code into your uat branch then use
Now you have merged your dev branch changes to uat branch (local repository)
Notes: Before merging changes, you can also preview them by using
$ git diff <source_branch> <target_branch>
8. Using Stash -
When moving between branches your local changes move with you. Sometimes you want to switch
branches but not commit or take those changes with you. The Git command stash lets you put
changes into a safe store.
To stash use
$ git stash
Creating Tags
Notes:
Everything whatever we are doing is on local repository (add/commit/tag/merge)
We need to push those changes later to remote repository.
By default, the git push command doesnt transfer tags to remote servers.
You will have to explicitly push tags to a shared server after you have created them.
This process is just like sharing remote branches
11. Logs
$ git log -author=author-name #To see commits of certain author
$ git log --pretty=oneline #compressed log where each commit is one line
12. Miscellaneous
Git has a stage area, git add will places the files in this area.
Everything whatever we are doing is locally we need to push that remote manually.
Commit hash commit hash is addressable via a hash (SHA-1 checksum).
This hash is calculated based on the content of the files, the content of the directories,
the complete history of up to the new commit, the committer, the commit message, and
several other factors.