Git is a version control (VCS) system for tracking changes to projects. These projects can be large-scale programs like the Linux kernel, but they can also be smaller scale projects like your own R development, homework assignments, papers, or thesis.
Using Git
- to add name
git config --global user.name yourname
- to add email
git config --global user.email youremail@yourdomain.com
- to check name
git config --global user.name
- to check email
git config --global user.email
- to initialize empty git repository
git init
- to show hidden files
ls - lart
- to create blank files
touch file_name
- to check status of file
git status
- to commit file
git commit
- to commit all files
git commit -a
- to add file in current repository
git add file_name
- to add all files
git add -A
-to add commit message
git commit -m "MESSAGE_HERE"
- to match with last commit, i.e., to recover losses
git checkout file_name
- to match all files with the last git commit
git checkout -f
- to check all commits
git log
- to check last 'n' commits (n should be a number)
git log -p -n
- to get difference between working file and staged file
git diff
- to get a list of the version history for the current branch.
ls
- to directly commit files (skip staging area)
git commit -a -m "MESSAGE_HERE
- to delete files
git rm file_name
- to remove file from staging area
git rm --cached file_name
- to get summarized status
git status -s
- to create ignore files
touch .gitignore
- to add new branches to git
git branch branch_name
- to switch between branches
git checkout branch_name
- to restore branch into master branch
git checkout master
- to merge branches into master branch (user must be in master)
git merge branch_name
- to create a branch and directly switch into it
git checkout -b branch_name
- to add remote git repository
git remote add URL_HERE
- to push branch into remote repository
git push repository_name branch_name
- to clone the repository into local setup from a URL
git clone URL_HERE
- to get remote URL from where the repository was cloned
git config --get remote.origin.url
- to unstage the file, but preserve the file contents
git reset file_name
- to undo all the commits after the specified commit and preserve the changes locally
git reset [commit]
- to discard all history and goes back to the specified commit
git reset –hard [commit]
- to show the metadata and content changes of the specified commit
git show [commit]
Hope you find it helpful and informative!
Do follow for more such blogs
Feel free to comment down your thoughts or suggestions if any.
Top comments (0)