-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitcomands.txt
65 lines (37 loc) · 3.49 KB
/
gitcomands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$ git : used to display common Git commands used in various situations with explanation
configuring user details in local
$ git config --global user.name "V M Aravind"
$ git config --global user.email [email protected]
$ git init : Create an empty Git repository or reinitialize an existing one in current directory
$ git status : Show the working tree status
$ git add filename : Add file contents to the index(stage)
$ git rm --cached <file>: to unstage
$ git commit -m "commit message" : Record changes to the repository
$ git log : Show commit logs
$ git checkout <commitid> : all files will change back to that version of files
$ git checkout main : all files will be restores to its latest commit version (if master is the name of branch, specify master in command instead of main)
$ git log --all : displays all the logs
$ git commit --amend -m "new message" : used to change the recent commit mesage
$ git show commitid : shows the change that has been introduced in the files after the specified commit
$ git branch newbranchname : create a new branch in the git. The new branch is created in the recent version where the head is pointing currently.Means it will contain all data from the recent commit.
$ git checkout branchname : switches to the specified branchranch
$ git merge branchname: merges the branch branchname to the current working branch. So if you want to merge branch2 to branch1, first you have to checkout to branch1, then git merge branch2
types of merges: fast forward merge, recursivse merge
$ git branch : shows all the branch and displays the current branch
$ git diff : shows the difference between the changes in files compared to last commit. compares files between now and last commit
$ git stash : delete the new changes and restores back to the last commit
$ git remote add origin gitssh/httpslink_of_repository : to add the remote repository to local for the purpose of connecting local to the remote.. used to pull or push codes between local and remote
Here origin is the name given by us for the remote repository..You can give any name
$ git remote : shows the name of addded remote repository
$ git remote -v : shows the links of fetch and push links of connected remote repository
$ git push name_of_remote_repository branch_name : pushes your local data in the specified branch to your remote repository under the same branch name
eg: git push origin main
here origin is the name given by us to remote repository when we connected it
$ git push origin : By default pushes all your branches to the origin
$ git clone remoterepository_clone_link : will clone the remository into your local under the same remote repository name in the current directory you are in
$ git pull origin master : pulls the latest code from repository added in the name of origin to the master branch in the local. {pull = fetch + merge}
###############
pull request : A pull request is an event in Git where a contributor asks a maintainer of a Git repository to review code they want to merge into a project.
.gitignore file : if you have a .gitignore file in your root of your local git, all the files specified in .gitignore will not tracked and pushed.. files that contain user data,hidden files, temp files etc
specify the file names in each line..you can also specify folders as well
when you create a new repository in github you can specify the gitignore file in settings which will give you predefined .gitignore for specific programming language