Gitvcs
Gitvcs
1. What is VCS? 2
1.1. Version Control System 2
1.2. Centralized VCS 2
1.3. Distributed VCS 2
2. Getting Started 2
2.1. Installing GIT 2
2.2. Setting up a Repository 2
2.2.1. Git init 2
2.2.1.1. Steps: 3
2.2.2. Git clone 3
2.2.3. Git config 3
2.3. Saving Changes 3
2.3.1. Git add 3
2.3.2. Git commit 4
2.4. Inspecting a Repository 4
2.4.1. Git status 4
2.4.2. Ignoring Files 4
2.4.3. Git log 4
2.5. Viewing Old Commits 5
2.5.1. Git checkout 5
2.6. Undoing Changes 6
2.6.1. Git revert 6
2.6.2. Git reset 6
2.6.3. Git clean 6
2.7. Rewriting History 6
2.7.1. Git commit --amend 6
2.7.2. Git rebase 7
3. Collaborating 7
3.1. Remote 7
3.2. Pull 7
3.3. Push 8
3.4. Fetch 8
3.5. Merge 8
3.6. Branch 8
4. Advanced Tips 9
4.1. Merging vs Rebasing 9
4.2. Reset, Checkout, and Revert 9
5. Reference 9
1
GIT (Version Control System)
1. What is VCS?
1.1. Version Control System
It is a software that helps software developers to work together and maintain a complete
history of their work. VCS are two types:-
1. Centralized VCS
2. Distributed VCS
2. Getting Started
2.1. Installing GIT
sudo apt update
sudo apt i nstall git
2.2.1.1. Steps:
mkdir project_name
cd project_name
git init
2
GIT (Version Control System)
Git init (creates .git directory that contains all the Git-related information for your project.)
3
GIT (Version Control System)
git commit
Commit the staged snapshot. This will launch a text editor prompting you for a commit
message. After you’ve entered a message, save the file and close the editor to create the
actual commit.
git commit -a
Commit a snapshot of all changes in the working directory. This only includes modifications
to tracked files.
git log
Display the entire commit history using the default formatting. If the output takes up more
than one screen, you can use Space to scroll and q to exit.
4
GIT (Version Control System)
project history.
Checking out a commit makes the entire working directory match that commit. This can be
used to view an old state of your project without altering your current state in any way.
Checking out a file lets you see an old version of that particular file, leaving the rest of your
working directory untouched.
5
GIT (Version Control System)
2.6. Undoing Changes
2.6.1. Git revert
The git revert command undoes a committed snapshot. But, instead of removing the commit
from the project history, it figures out how to undo the changes introduced by the commit and
appends a new commit with the resulting content.
This prevents Git from losing history, which is important for the integrity of your revision
history and for reliable collaboration. More Explanation
Commands:
When you undo with git reset(and the commits are no longer referenced by any ref or the
reflog), there is no way to retrieve the original copy—it is a permanent undo. More
Explanation
Commands
eset <file>
git r
git r eset --hard
git r eset <commit>
Commands:
git clean -n
6
GIT (Version Control System)
can be used to simply edit the previous commit message without changing its snapshot.)
3. Collaborating
3.1. Remote
The git remote command lets you create, view, and delete connections to other repository.
git remote
List the remote connections you have to other repositories.
git remote -v
Same as the above command, but include the URL of each connection
git remote add <name> <url>
Create a new connection to a remote repository.
git remote rm <name>
Remove the connection to the remote repository called <name>
git remote rename <old-name> <new-name>
Rename a remote connection from <old-name> to <new-name>
3.2. Pull
Merging upstream changes into your local repository is a common task in Git-based
collaboration workflows
git pull <remote>
Fetch the specified remote copy of the current branch and immediately merge it into the local
copy. This is same as
7
GIT (Version Control System)
3.3. Push
Pushing is how you transfer commits from your local repository to a remote repo. It’s the
counterpart to git fetch, but whereas fetching imports commits to local branches, pushing
exports commits to remote branches.
git push <remote> <branch>
Push the specified branch to <remote>, along with all f the necessary commits and internal
objects. This created a local branch in the destination repository. To prevent you from
overwriting commits, git won’t let you push when it results in a non-fast-forward merge in
the destination repository.
ush <remote> ---force
git p
git p ush <remote> --all
git p ush <remote> --tags
3.4. Fetch
The git fetch command imports commits from a remote repository into your local repo. The
resulting commits are stored as remote branches instead of the normal local branches that
we’ve been working with.
git fetch <remote>
Fetch all of the branches from the repository. This also download all of the required commits
and files from the other repository.
git fetch <remote> <branch>
3.5. Merge
3.6. Branch
git branch
List all of the branches in your repository. This is synonymous with git branch --list
git branch <branch>
Create a new branch called <branch>. This does not check out the new branch.
git branch -d <branch>
Delete the specified branch. This is s “safe” operation in that Git prevents you from deleting
the branch if it has unmerged changes.
git branch -D <branch>
8
GIT (Version Control System)
Force delete the specified branch, event if it has unmerged changes. This is the command to
use if you want to permanently throw away all of the commits associated with a particular
line of development.
git branch -m <branch>
Rename the current branch to <branch>
git branch -a
List all remote branches.
4. Advanced Tips
4.1. Merging vs Rebasing
2. http://www.vogella.com/tutorials/Git/article.html
3. https://guides.github.com/activities/hello-world/
4. http://www.sitepoint.com/git-for-beginners/