0% found this document useful (0 votes)
1 views10 pages

Git Documentation

This document provides a comprehensive guide on configuring and using Git through the command prompt, including installation, setting user information, initializing repositories, and managing file changes. It outlines essential commands for tracking changes, resolving conflicts, and synchronizing with remote repositories. Additionally, it includes explanations of key Git terminologies and commands for effective version control management.

Uploaded by

jpbankadnan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views10 pages

Git Documentation

This document provides a comprehensive guide on configuring and using Git through the command prompt, including installation, setting user information, initializing repositories, and managing file changes. It outlines essential commands for tracking changes, resolving conflicts, and synchronizing with remote repositories. Additionally, it includes explanations of key Git terminologies and commands for effective version control management.

Uploaded by

jpbankadnan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Git configuration using command prompt ::

1. Download and install latest version of git from http://git-scm.com/downloads


2. After installation, edit git configuration file using command prompt.

git config --global user.name "Biplob Hossain"​


git config --global user.email "[email protected]"
git config --global core.editor emacs
git config --global merge.tool vimdiff

3. Check your settings


​ ​ git config --list

4. From time to time there are files you don't want git to track.So that you can ignore those files using
.gitignore file. Add selected files into the .gitignore file and add it to the gitconfig file.

To add this to your config, run git config --global core.excludesfile ~/.gitignore_global

5. Now your environment is ready to use git.

Choose your action from following::

* Initializing a repository in existing directory::


​ # Create an empty directory in your working area/local drive or choose an existing project
directory to initialize.
​ # On terminal, go to the directory and run, git init.

* Cloning existing directory::


​ Run, git clone [url]​ e.g git clone git://github.com/schacon/grit.git
​ ## url - repository url in git where project file exists.

Now you have a git project to work with git.


* Check project status from local directory(master branch -- in terms of git)
​ Run, git status ​
## display your local changes. A- added, M - Modified, D -Deleted, C- conflict
​ git status -s ## Display changed file names and statuses only
* Tracking new file::
​ run, git add . ## this will track all newly added files and prepare them to commit
​ git add [filename] ## to track individual file.
* Get differences::
​ You can check the differences among branches.

​ run , git diff ## show diff of unstaged changes


​ git diff --cached ## show dif of staged and unstaged changes.
git diff HEAD ## Show diff of working directory and last commit
git diff --stat ## show summary of changes instead of a full diff

* Record changes::
​ run, git commit ## records a snapshot of local changes.
​ git add . && git commit -a -m “Your commit message”
​ ​ ## this will add untracked file into git index and will commit all changes into the
intermediary branch origin/master. This will record a change and add it to the git database.This will not
update your code to the origin or git repository. Commit message is mendatory.

* Add local changes to the git repository::


​ After every commit , you must run following line to update server or origin.
​ ​ git push

* Undo Changes::
git reset ## Undo changes and commit.

git reset HEAD ## undo the last commit and unstage the files

git reset --soft ##undo the last commit

git reset --hard ##undo the last commit, unstage files AND undo any changes in the working
directory
* Override server files with your local::
​ git checkout [directoryname]
​ git checkout [filepath]

* Receives update from server::


​ git fetch
​ ## synchronize you with another repo, pulling down any data that you do not have locally and
giving you bookmarks to where each branch on that remote was when you synchronized.

git pull
## fetch from a remote repo and try to merge into the current branch.This will update your local
files with server files.
*Inspection and Comparison::
​ git log
​ ## Displays your commit history
​ git log --oneline ## commit history in one line
​ git log -p ​ ## commit history with changes.

* Resolve Conflict ::
​ several options you have to resolve conflict.
​ # you can checkout previous update of the conflicted file.To do this,
​ ​ run, git checkout [filename]
​ # you can reset your code base with server.To do this,
​ ​ run, git reset --hard

git checkout --theirs [filename] ## get server update of the file
​ git checkout --ours [filename] ## update server with your changes.
​ then commit and push.

* Clean Up local directory::


​ run, git gc ## will remove garbase file from local directory.

For further details,


​ http://gitref.org
http://git-scm.com/
http://www.kernel.org/pub/software/scm/git/docs/v1.7.3/user-manual.html
https://help.github.com

ignore .DS_Store forever in GIT


With a couple of little commands, you?ll be able to ignore the .DS_Store files forever from your git repositories on
mac!
The following command will add the .gitignore file to the git configuration
git config --global core.excludesfile ~/.gitignore
then, the following, will add the .DS_Store to the list
echo .DS_Store >> ~/.gitignore
Git Terminologies

Git
# Command Description

1 Bare Repository without a working directory.


Repository

2 Branch A branch is an active area of development in Git. The most recent


commit shows the tip of the branch.

3 Blame Describes the last modification to every line in the file. Shows
Revision, Author & Time.

4 Checkout This refers to the process in which any given commit is selected from
the repository and the state of the associated file and the directory
tree is recreated in the working directory.

5 Commit This is a single point in Git history which holds the information about
a changeset.

6 Diff A Diff is the difference in changes between two Commits, or saved


changes.

7 Detached The state in which a specific commit is checked out instead of a


Head branch.

8 Fetch Fetching means to get latest changes in the branch and the
local/remote repos.

9 Fork By Forking the repository, you will be able to add Commits and
create Pull Requests.

1 Hash A unique SHA1 code for every Commit


0

1 Head A named reference to the Commit at the tip of a Branch


1

1 Index A collection of files with state information.


2

1 Merge To bring out the content of another Branch in the current Branch.
3

1 Master The default development Branch in Git


4

1 Origin The default Upstream Repository


5

1 Pull Suggests changes into the Master Branch


6 Request

1 Push Pushes new changes after Committing them


7

1 Repository A collection of Commits, Branches and Tags to identify Commits.


8

1 Working The tree of actual checked out files


9 Tree

Git Configuration
# Git Command Description

1 git config –global Set the username to be used for all actions
user.name

2 git config –global Set the email to be used for all the actions.
user.email

3 git config –global alias. Create a shortcut for the Git command.

4 git config –system Set the text editor for all the command actions.
core.editor

5 git config –global –edit Open global configuration file in the text editor for
manual editing.

6 git config –global Enable helpful colourization of command line outputs.


color.ui auto

Set Up a Git Repository


# Git Command Description
1 git init Initialize an empty Git repo in the
current project.

2 git clone (Repo URL) Clone the repository from GitHub to the
project folder.

3 git clone (Repo URL) (Folder ) Clone the repository into a specific
folder.

4 git remote add origin Create a remote repo pointing on your


https://github.com/username/(repo_n existing GitHub repository.
ame).git

5 git remote Shows the name of remote repositories.

6 git remote -v Shows the name and the URL of the


remote repositories.

7 git remote rm (remote repo name) Removes the remote repository.

8 git remote set-url origin (git URL) Changes the URL of the repository.

9 git fetch Get the latest changes from the origin


but not merge.

1 git pull Get the latest changes from the origin


0 and merge them.

Local File Changes


# Git Command Description

1 git add (file name) Add the current changes to the file to staging.

2 git add . Add the whole directory changes to staging (no


delete files).

3 git add -A Add all new, modified and deleted files to


staging.

4 git rm (file_name) Removes the file and untracks (stop tracking) it.

5 git rm –cached (file_name) Untracks the current file.


6 git mv (file_name) Changes the filename and prepare it for Commit.
(new_file_name)

7 git checkout <deleted file Recovers the deleted file and prepares it for
name> Commit

8 git status Shows the status of the modified files.

9 git ls-files –other –ignored Shows the list of all ignored files.
–exclude-standard

1 git diff Shows unstaged changes in the index and the


0 working directory.

1 git diff –staged Shows file differences between staging and the
1 last file version.

1 git diff (file_name) Shows changes in a single file compared to the


2 last Commit.

Declare Commits
# Git Command Description

1 git commit -m Commits the changes with a custom message.


“(message)”

2 git commit -am Adds all changes to staging and commits them with a
“(message)” custom message.

3 git checkout Switch to the provided Commit.

4 git show Outputs the metadata and content changes of the


specified Commit.

5 git reset –hard Discard all the history and changes back to a given
Commit.

6 git reset –hard Head Discards all local changes in the working directory.

7 git log Shows the history of changes.

8 git log -p Shows the full display of each Commit.


9 git log -oneline Shows the list of Commits with a simple message.

1 git log –follow List the history for the current file.
0 (file_name)

1 git blame (file_name) Shows all changes along with the name of the user.
1

1 git stash Temporarily saves all modified tracked files.


2

1 git stash pop Restores the most recently stashed files.


3

1 git stash list List all stash changedsets.


4

1 git stash apply Apply the latest stashed contents.


5

1 git stash drop Discard the most recently stashed files


6

1 git stash apply (stash id) Re-apply a specific stash content by ID.
7

1 git stash drop (stash_id) Drop a specific stash content by ID.


8

1 git push Push changes to the Origin.


9

1 git push origin Push branch to the Origin.


6 (branch_name)

1 Git push -f origin Force pushes the changes to the Origin.


7 (branch_name)

1 git tag (tag_name) Define a tag for a version.


8

1 git push Push changes to the Origin.


9

Branching
# Git Command Description

1 git branch Shows the list of all branches.

2 git branch Creates a new branch.

3 git branch -m Renames the branch.

4 git branch -a List all branches, local and remote.

5 git checkout -b Creates a branch and switch to it.

6 git checkout Switch to the provided branch.

7 git checkout -b Get a remote branch from origin to the local directory.
origin/

8 git branch -d Delete the specified branch.

9 git merge Merge the current branch into the master (first checkout to
master)

1 git rebase Takes all the changes of the branch and restate on others.
0

1 git rebase Rebase the current branch onto the base. Base can be a Commit
1 ID or a branch name.

1 git fetch Fetches the specified branch from the repository.


2 remote

1 git diff .. Shows the differences between two branches.


3

1 git pull –rebase Fetches the remote copy of the current branch and rebases it
4 into the local copy.

1 git push –all Push all the local branches to the specified remote repository.
5
Necessary Git Commands
●​ git submodule update --init --recursive --remote

Accidentally created a git submodule?


●​ If there is a .git folder: git rm --cached folder_name; git add folder_name
●​ If there is no .git folder: git rm --cached --ignore-unmatch folder_name; git add
folder_name

Syncing a fork
●​ git remote add upstream https://github.com/otheruser/repo.git
●​ git remote -v
●​ git fetch upstream
●​ git checkout master
●​ git rebase upstream/master
●​ git push -f origin master (You only need to use the -f the first time after you've
rebased.)

You might also like