-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_commands.txt
executable file
·98 lines (56 loc) · 2.87 KB
/
git_commands.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
echo "git name" >> README.md
git clone https://github.com/anandhank/<git name>
create a new repository on the command line in local and add it to git hub (Create a github repository in github site)
git init
git add README.md
git commit -m "first commit"
git branch -M master
git remote add origin https://github.com/anandhank/<git name>
git push -u origin master
for further commits:
git add .
git commit -m "update commit"
git branch -M master
git push -u origin master
for storing pwd and user id of git
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
See What Branch You're On Run this command:
git status
List All Branches (NOTE: The current local branch will be marked with an asterisk (*).)
To see local branches, run this command:
git branch
To see remote branches, run this command:
git branch -r
To see all local and remote branches, run this command:
git branch -a
Create a New Branch Run this command (replacing my-branch-name with whatever name you want):
git checkout -b my-branch-name
You're now ready to commit to this branch. Switch to a Branch In Your Local Repo - Run this command:
git checkout my-branch-name
Switch to a Branch That Came From a Remote Repo, To get a list of all branches from the remote, run this command:
git pull
Run this command to switch to the branch:
git checkout --track origin/my-branch-name
Push to a Branch, If your local branch does not exist on the remote, run either of these commands:
git push -u origin my-branch-name
git push -u origin HEAD
NOTE: HEAD is a reference to the top of the current branch, so it's an easy way to push to a branch of the same name on the remote. This saves you from having to type out the exact name of the branch!
If your local branch already exists on the remote, run this command:
git push
Merge a Branch, You'll want to make sure your working tree is clean and see what branch you're on. Run this command:
git status
First, you must check out the branch that you want to merge another branch into (changes will be merged into this branch). If you're not already on the desired branch, run this command:
git checkout master
NOTE: Replace master with another branch name as needed.
Now you can merge another branch into the current branch. Run this command:
git merge my-branch-name
NOTE: When you merge, there may be a conflict. Refer to Handling Merge Conflicts (the next exercise) to learn what to do.
Delete Branches, To delete a remote branch, run this command:
git push origin --delete my-branch-name
To delete a local branch, run either of these commands:
git branch -d my-branch-name
git branch -D my-branch-name
NOTE: The -d option only deletes the branch if it has already been merged. The -D option is a shortcut for --delete --force, which deletes the branch irrespective of its merged status.